Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations IDS on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to choose point in assembly and detrmine its coordinates ? 1

Status
Not open for further replies.

verga

Automotive
Nov 6, 2011
7
Hello,
I am new in SolidWorks API.
I don't know how through VBA choose specific point on assembly ( in this case it is end of robotic arm ).
And check its coordinates which will be used later.

Could someone give me a working example which I could analize ?

Thank you in advance.

P.S. This is my first question in this forum.
 
Replies continue below

Recommended for you

You might try looking the the API help for examples. For example if you search for vertex you may find an example or two on how to enumerate vertices or gather a vertex' properties.

How you are going to choose this point is an important detail.



TOP
CSWP, BSSE
Phenom IIx6 1100T = 8GB = FX1400 = XP64SP2 = SW2009SP3
"Node news is good news."
 
Maybe it will be better to draw a point at the end of the arm and get coordinates of this point ?
I tried to select such point but with no result. Only could select sketch on which it was drawn.
 
Sorry for rush.

I solved right point selection by drawing it and selecting by Part.Extension.SelectByID2("Point@3D sketch", "EXTSKETCHPOINT", 0, 0, 0, False, 0, Nothing, 0)

Works fine, but with this selection example of getting coordinates from API help doesn't seem to work.

With
Dim instance As IMeasure
Dim value As Double

...
value = instance.X

it crashes and returns "Run-time error '91' : "Object variable or With block variable not set"

everything is declared so I don't know why it is asking for variables.
 
I have made it through to macro like this :

Dim swApp As SldWorks.SldWorks
Dim Part As ModelDoc2
Dim SelMgr As SldWorks.SelectionMgr

Sub main()
Dim point As Variant
Set swApp = Application.SldWorks

Set Part = swApp.ActiveDoc
boolstatus = Part.Extension.SelectByID2("Point7@Szkic 3D10", "EXTSKETCHPOINT", 0, 0, 0, False, 0, Nothing, 0)

Set SelMgr = Part.SelectionManager

point = SelMgr.GetSelectionPoint2(1, -1)

MsgBox (point(0) & vbTab & point(1) & vbTab & point(2))

End Sub

It selects the point in my assembly , always return " 0, 0, 0".
But when I delete SelectByID2 line and manually choose point it shows good coordinates.
What is made wrong in this code ? I am new in API and this is big problem for me at the moment.

I appreciate any help.
 
This works:
Code:
Dim swApp As SldWorks.SldWorks
Dim Part As ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim point As Variant
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long

Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
'boolstatus = Part.Extension.SelectByID2("", "VERTEX", -0.0254, 0, 0, False, 0, Nothing, 0) 'Have to comment out this line if working interactive
Set SelMgr = Part.SelectionManager

point = SelMgr.GetSelectionPoint2(1, -1)

MsgBox (point(0) & vbTab & point(1) & vbTab & point(2))

End Sub

TOP
CSWP, BSSE
Phenom IIx6 1100T = 8GB = FX1400 = XP64SP2 = SW2009SP3
"Node news is good news."
 
It works only when interactive.
I think problem is in zeros from selectbyID2.
They aren't used to select specific part, because it is selected by name, but I think it puts 0 values in X Y and Z variables.
Maybe there is another command to select without those parameters?
 
Hello,

I finally found the way and used Part.Extension.CreateMeasure. It gives back good coordinates when used .X , .Y and .Z parameters.

Thank you
 
Sure

Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
boolstatus = Part.Extension.SelectByID2("Point7@Szkic 3D10", "EXTSKETCHPOINT", 0, 0, 0, False, 0, Nothing, 0)
Set swSelMgr = Part.SelectionManager

Set Measure = Part.Extension.CreateMeasure

boolstatus = Measure.Calculate(Nothing)

X = (Measure.Z * 1000)
Y = (Measure.Y * 1000)

Part.ClearSelection2 True

because I needed only 2 dimensions and they had to be switched to make nice graph.

Works fine :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor