Transform part relative to UCS
Hello,
I want to position a part relative to an UCS in VBA. I Do the folowing:
Sets UCS
Define the Transformation
Then I would like to use The WCSToUCS, but this gives me troubles.
Regards
Michael
Comments
-
Hi Michael
Here comes a example how to position relative
This example will set part p1 to ucs and then position part p2 relativ ucs 100mm in X and 100 mm in Y
Sub RelativeUCS()
Dim p1 As Part
Dim p2 As Part
Dim t As New Transform
t.x = 0.1
t.y = 0.1
t.z = 0
t.Rx = 0
t.Ry = 0
t.Rz = 0
Set p1 = ActiveStation.Parts(1)
Set p2 = ActiveStation.Parts(2)
ActiveStation.UCS = p1
p2.Transform = UCSToWCS(t)
End SubPer Svensson
Company Specialist
ABB Automation Technology Products0 -
Or here is another example:
Sub RelativeMove()
Dim tfmT As New Transform
tfmT.x = 0
tfmT.y = 0
tfmT.z = 1
tfmT.Rx = 0
tfmT.Ry = 0.785398163397448 '45?
tfmT.Rz = 0.785398163397448 '45?
Dim prt1 As Part
Set prt1 = ActiveStation.Parts.Add
prt1.Transform = tfmT
prt1.ShowCoordinateSystem = True 'displays the parts coord in the gfx
MsgBox prt1.Name & " created."
Dim prt2 As Part
Set prt2 = ActiveStation.Parts.Add
prt2.ShowCoordinateSystem = True 'displays the parts coord in the gfx
MsgBox prt2.Name & " created."
ActiveStation.UCS = prt1
MsgBox prt1.Name & " set as UCS."
tfmT.x = 0
tfmT.y = 0
tfmT.z = 0.5
tfmT.Rx = 0
tfmT.Ry = 0
tfmT.Rz = 0
prt2.Transform = UCSToWCS(tfmT)
MsgBox prt2.Name & " placed 500 mm relative to direction of " & prt1.Name & "."
MsgBox "Cleanup."
ActiveStation.UCS = ActiveStation 'resets the UCS
prt1.Delete
prt2.Delete
MsgBox "Cleanup finished."End Sub
John
Developer Center0 -
Another example that use the RobotStudio Math Util (no need to set UCS). You need to add a reference to the RobotStudio Math util (tools
eferences)This example only handles parts , but I think you get the idea, and it moves part2(p2) 100mm in part1(p1) x direction.
If you have for example a lot of stuff in your station using the Math Util is much more faster than setting the UCS all the time.
Sub MoveRelativeTo(MoveObject As Part, RelativeObject As Part, DirectionValues As Variant)
Dim tmpTransform As Transform
Dim tmpVector As RsMathVector
Dim tmpMatrix As RsMathMatrixOn Error Resume Next
Set tmpTransform = RelativeObject.Transform
tmpMatrix = RsMath_TransformToMatrix(tmpTransform)
tmpVector.x = UnitToAPI(rsQuantityLength, DirectionValues(0))
tmpVector.y = UnitToAPI(rsQuantityLength, DirectionValues(1))
tmpVector.z = UnitToAPI(rsQuantityLength, DirectionValues(2))
tmpMatrix.pos = RsMath_mult_mat_vec(tmpMatrix, tmpVector)
MoveObject.Transform.Position = RsMath_MatrixToTransform(tmpMatrix).PositionActiveStation.Refresh
End Sub
Sub TestRelative()
Dim p1 As Part
Dim p2 As Part
Dim Values(0 To 2) As Variant
'x,y,z directions
Values(0) = 100
Values(1) = 0
Values(2) = 0
Set p1 = ActiveStation.Parts(1)
Set p2 = ActiveStation.Parts(2)
MoveRelativeTo p2, p1, Values
End SubPer Svensson
Company Specialist
ABB Automation Technology Products0
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