Kevin Sturge

How to select a body and other fun stuff

Discussion created by Kevin Sturge on Sep 3, 2015
Latest reply on Sep 9, 2015 by Kevin Sturge

Hello, In the following macro I would like to select the (only) solid body and use that as the object to rotate with the (move copy action)

For those curious about the purpose... well basically we use 2.5 axis mills, and we want some of the parts in question to be "wedged" about the center of gravity along the y axis, by a user input driven value... that way the part can be re-raised to zero on the z and trick the machine into thinking that the empty space under the wedged section should be solid...

I've gotten pretty far on my lonesome.

If you're curious about the userform I used i would be glad to add pictures and the code for that ( basically just shooting values to the main proc. )


So I know that the rotate section works (fantastically) when I name the solid body something but it is illogical to rename every solid body every time. So My Question is:

1.) Can I choose to rename a solid body to something before selecting it? (would solve all my problems)

2.) If not how do I select the Soid body (or all solid bodies Since there will only ever be one) and use the "Move copy" action against it?



' **********************************************************************************************

' Macro used to rotate the Part in question about the specified point (COG)
'     which should be defined by cog macro.
'      the origin should be moved to the cog so it is just Rotating about the y




'     Part is a .sldprt

'     The solid body  may be named a wide array of things due to the possibility of having to use the mirror macro beforehand




'     Part can be rotated with the "copy move" actions

'     There is only one Solid body in the doc




'     Teh part is rotated by the radian equivalent of the user input degrees or millimeters(lift)


' **********************************************************************************************

Dim swApp As Object

Dim Part As Object

Dim boolstatus As Boolean

Dim longstatus As Long, longwarnings As Long

Public Y As Double

Public X As Double


'Show the userform


Sub GUI()


End Sub


'Proceedure to grab values and appy the change from degrees to radians.


Public Sub MakeWedge(ByVal o As Boolean, ByVal t As String)

'MsgBox Userinput & o & t

Dim mm_Option As Boolean

mm_Option = o

Dim result As Double

If mm_Option = True Then

    result = t * 1.5 * 0.0174532925


    result = t * 0.0174532925

End If


MsgBox result

Call rotate(result)

End Sub



Sub rotate(ByVal res As Double)


The two methods I am exploring




'this works if the solid body is named something

boolstatus = Part.Extension.SelectByID2("SolidBodyName", "SOLIDBODY", 0, 0, 0, True, 0, Nothing, 0)

Part.ClearSelection2 True

boolstatus = Part.Extension.SelectByID2("SolidBodyName", "SOLIDBODY", 0, 0, 0, False, 1, Nothing, 0)




'Does this work to select all bodies...?

'boolstatus = Part.Extension.SketchBoxSelect("0.000000", "0.000000", "0.000000", "0.000000", "0.000000", "0.000000")





'"Move Copy" action


'Dim myFeature As Object

myFeature = Part.FeatureManager

Set myFeature = swSelData.FeatureManager.InsertMoveCopyBody2(0, 0, 0, 0, 0, 0, 0, 0, res, 0, False, 1)

End Sub