×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

How to choose point in assembly and detrmine its coordinates ?

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.
  

RE: How to choose point in assembly and detrmine its coordinates ?

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
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 ?

(OP)
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.
 

RE: How to choose point in assembly and detrmine its coordinates ?

(OP)
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.
 

RE: How to choose point in assembly and detrmine its coordinates ?

(OP)
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.
 

RE: How to choose point in assembly and detrmine its coordinates ?

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
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 ?

(OP)
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?  

RE: How to choose point in assembly and detrmine its coordinates ?

(OP)
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   

RE: How to choose point in assembly and detrmine its coordinates ?

(OP)
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 :)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources