Copy Part
Hello
I am attempting to use the API to copy a part in the active station.
The following code works well, except when the part has many entities, it takes some time to complete.
Private Sub CopyPart()
Dim p As Part
Dim e As Entity
Dim cbpCommandBarPopup As RSEXT.CommandBarPopup
ActiveStation.UCS = ActiveStation
Set p = ActiveStation.Parts.Add
'catches the edit menu for the copy paste commands
Set cbpCommandBarPopup = RSE.CommandBars("Menu Bar").Controls("Edit")
'Copies the parts
ActiveStation.Selections.RemoveAll
For Each e In ActiveStation.Parts("part_to_copy").Entities()
ActiveStation.Selections.Add e
Next e
cbpCommandBarPopup.Controls("Copy").Execute
ActiveStation.Selections.RemoveAll
ActiveStation.Selections.Add p
cbpCommandBarPopup.Controls("Paste").Execute
End Sub
How does one just copy a part, without haveing to traverse through all of the entities?
I tried the following without success:
Private Sub CopyPart()
Dim p As Part
Dim cbpCommandBarPopup As RSEXT.CommandBarPopup
'catches the edit menu for the copy paste commands
Set cbpCommandBarPopup = RSE.CommandBars("Menu Bar").Controls("Edit")
'Copy the part
ActiveStation.Selections.RemoveAll
ActiveStation.Selections.Add ActiveStation.Parts("part_to_copy")
cbpCommandBarPopup.Controls("Copy").Execute
ActiveStation.Selections.RemoveAll
ActiveStation.Selections.Add ActiveStation
cbpCommandBarPopup.Controls("Paste").Execute
End Sub
The key must be the line :ActiveStation.Selections.Add ActiveStation
But I have tried many different things without success.
I was successful in copying into an assembly by just the part reference, but how do you paste into the components part of the station?
Looking forward to your reply.
Tom
PACs Application Engineer
Comments
-
You don't.
It's not possible from the API to directly select the 'components' in the browser.
But... If you want to do something really 'baaad' you could always use the "sendkeys" to go to the components.
So my recomendation would be to do it like you did first. Put it in an assembly and be happy.
John
Developer Center0 -
A bit more to the copy paste issue - I tried the same thing, using the CommandBarPopUp approach, and it worked fine when I ran the macro, but during run time, 'Operation is not allowed'.
Is there a way to copy/paste during run time? (ie for adding a new box to a conveyor by copying a reference box, rather than creating a new one from scratch)
Dean Thomas
ABB Support Engineer
Channel Partners Australia0 -
Hello Dean,
Here comes two code examples that work when you "Play" a simulation. I'm running on RobotStudio 3.0, what version do you have?
Sub CopyExample()
'When you copy you need to copy on child level and paste on parent level
Dim prtP1 As Part
Dim prtP2 As Part
Dim entE As Entity
Dim tfmT As New Transform
'We will now create two parts, one with a box and one that is empty
Set prtP1 = ActiveStation.Parts.Add
Set prtP2 = ActiveStation.Parts.Add
Set entE = prtP1.CreateSolidBox(tfmT, 0.5, 0.5, 0.5)
MsgBox "2 parts 1 entity"
'To be able to copy stuff we need to have them selected
ActiveStation.Selections.RemoveAll
ActiveStation.Selections.Add entE
MsgBox "The box is selected"
'Since copy doesn't exist on the object we need to call the menu
Application.RSE.CommandBars("Menu Bar").Controls("Edit").Controls("Copy").Execute
'Now we need to select the other part
ActiveStation.Selections.RemoveAll
ActiveStation.Selections.Add prtP2
MsgBox "2nd part selected"
'Finally we paste in the object, again from the menu
Application.RSE.CommandBars("Menu Bar").Controls("Edit").Controls("Paste").Execute
MsgBox "Now the second part should have a box copy"
End SubSub CopyExample2()
'When you copy you need to copy on child level and paste on parent level
Dim prtP1 As Part
Dim prtP2 As Part
Dim entE As Entity
Dim tfmT As New Transform
'We will now create two parts, one with a box and one that is empty
Set prtP1 = ActiveStation.Parts.Add
Set prtP2 = ActiveStation.Parts.Add
Set entE = prtP1.CreateSolidBox(tfmT, 0.5, 0.5, 0.5)
MsgBox "2 parts 1 entity"
'To be able to copy stuff we need to have them selected
ActiveStation.Selections.RemoveAll
ActiveStation.Selections.Add entE
MsgBox "The box is selected"
'Since copy doesn't exist on the object we need to call the menu
'Application.RSE.CommandBars("Menu Bar").Controls("Edit").Controls("Copy").Execute
Dim cbc As CommandBarControl
Set cbc = Application.RSE.CommandBars.FindControl(, 57634)
cbc.Execute
'Now we need to select the other part
ActiveStation.Selections.RemoveAll
ActiveStation.Selections.Add prtP2
MsgBox "2nd part selected"
'Finally we paste in the object, again from the menu
'Application.RSE.CommandBars("Menu Bar").Controls("Edit").Controls("Paste").Execute
Set cbc = Application.RSE.CommandBars.FindControl(, 57637)
cbc.Execute
MsgBox "Now the second part should have a box copy"
End Sub'To get hold of the ID's above run the following.
Sub id()
Ulrika Mor?n38036,4532638889
MsgBox Application.RSE.CommandBars("Menu Bar").Controls("Edit").Controls("Paste").id
MsgBox Application.RSE.CommandBars("Menu Bar").Controls("Edit").Controls("Copy").id
End Sub0
Categories
- All Categories
- 5.5K RobotStudio
- 396 UpFeed
- 18 Tutorials
- 13 RobotApps
- 297 PowerPacs
- 405 RobotStudio S4
- 1.8K Developer Tools
- 250 ScreenMaker
- 2.8K Robot Controller
- 314 IRC5
- 59 OmniCore
- 7 RCS (Realistic Controller Simulation)
- 794 RAPID Programming
- AppStudio
- 3 RobotStudio AR Viewer
- 18 Wizard Easy Programming
- 105 Collaborative Robots
- 5 Job listings