How to choose point in assembly and detrmine its coordinates ?
How to choose point in assembly and detrmine its coordinates ?
(OP)
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.
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.






RE: How to choose point in assembly and detrmine its coordinates ?
How you are going to choose this point is an important detail.
TOP
CSWP, BSSE
www.engtran.com www.niswug.org
www.linkedin.com/in/engineeringtransport
Phenom IIx6 1100T = 8GB = FX1400 = XP64SP2 = SW2009SP3
"Node news is good news."
RE: How to choose point in assembly and detrmine its coordinates ?
I tried to select such point but with no result. Only could select sketch on which it was drawn.
RE: How to choose point in assembly and detrmine its coordinates ?
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.
RE: How to choose point in assembly and detrmine its coordinates ?
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.
RE: How to choose point in assembly and detrmine its coordinates ?
CODE
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
www.engtran.com www.niswug.org
www.linkedin.com/in/engineeringtransport
Phenom IIx6 1100T = 8GB = FX1400 = XP64SP2 = SW2009SP3
"Node news is good news."
RE: How to choose point in assembly and detrmine its coordinates ?
TOP
CSWP, BSSE
www.engtran.com www.niswug.org
www.linkedin.com/in/engineeringtransport
Phenom IIx6 1100T = 8GB = FX1400 = XP64SP2 = SW2009SP3
"Node news is good news."
RE: How to choose point in assembly and detrmine its coordinates ?
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?
RE: How to choose point in assembly and detrmine its coordinates ?
I finally found the way and used Part.Extension.CreateMeasure. It gives back good coordinates when used .X , .Y and .Z parameters.
Thank you
RE: How to choose point in assembly and detrmine its coordinates ?
TOP
CSWP, BSSE
www.engtran.com www.niswug.org
www.linkedin.com/in/engineeringtransport
Phenom IIx6 1100T = 8GB = FX1400 = XP64SP2 = SW2009SP3
"Node news is good news."
RE: How to choose point in assembly and detrmine its coordinates ?
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 :)