Find specific line in part 2d sketch using vba

Find specific line in part 2d sketch using vba

danijel.radenkovic
Collaborator Collaborator
971 Views
6 Replies
Message 1 of 7

Find specific line in part 2d sketch using vba

danijel.radenkovic
Collaborator
Collaborator

Hello Autodesk Inventor users,

For example, every sketch dimension has a standard parameter name such as d0,d1...dx. Did Inventor also give a name to every sketch line that you created?

I would like to know is it possible to find specific line in 2d sketch which is already created? (Notice that I don't want to create a new one, I want to find old one that is already created)

 

Best regards

Danijel

Inventor 2018/Windows 10 x64
If this information was helpful, please consider marking it as an Accepted Solution by using the Accept as Solution. Kudos are also gladly accepted.
0 Likes
Accepted solutions (1)
972 Views
6 Replies
Replies (6)
Message 2 of 7

CadUser46
Collaborator
Collaborator

Natively No but if the lines are created by you in the API i believe you can name them via attributes although it's not something i have done.


Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

---------------------------------------------------------------------------------------------------------------------------
Inventor 2010 Certified Professional
Currently using 2023 Pro
0 Likes
Message 3 of 7

BrandonBG
Collaborator
Collaborator

The individual lines are numbered as items in the collection SketchLines; however, the numbers don't indicate anything.

 

In VBA, use this rule and add a watch to "obj".

 

Sub SelectSomething()
    Dim obj As Object
    Set obj = ThisApplication.ActiveDocument.SelectSet(1)
End Sub

 It's really useful for poking around and seeing what you can get at with the API.

 

Brandon

0 Likes
Message 4 of 7

ekinsb
Alumni
Alumni

Items in a sketch are not named and should not be considered to be in any kind of consistent order.  You're correct that you can get a list of lines, but you should rely on the order in how they're returned in that list.

 

There are a couple of potential solutions.  The first was already mentioned and that is to use attributes.  Attributes provide a way for you to attach information to any object.  A common use of attributes is as a naming mechansim because you can attach information and then search for all objects that have specific information.  Using this, lets you quickly find the line that you've "named".

 

The second possible solution is to somehow identify the line geometrically.  For example if you know the sketch is a rectangle and you want the "bottom" line you can look at the end points of the lines and find the one that has equal X values and the lowest Y values.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 5 of 7

danijel.radenkovic
Collaborator
Collaborator

@ekinsb wrote:

Items in a sketch are not named and should not be considered to be in any kind of consistent order.  You're correct that you can get a list of lines, but you should rely on the order in how they're returned in that list.

 

There are a couple of potential solutions.  The first was already mentioned and that is to use attributes.  Attributes provide a way for you to attach information to any object.  A common use of attributes is as a naming mechansim because you can attach information and then search for all objects that have specific information.  Using this, lets you quickly find the line that you've "named".

 

The second possible solution is to somehow identify the line geometrically.  For example if you know the sketch is a rectangle and you want the "bottom" line you can look at the end points of the lines and find the one that has equal X values and the lowest Y values.



Hello Mr. Ekins,

I have never worked with attaching the information on the item. Is it something like Inventor note (see image)?

Would you like to provide some small example?

 

Regards

Danijel

Inventor 2018/Windows 10 x64
If this information was helpful, please consider marking it as an Accepted Solution by using the Accept as Solution. Kudos are also gladly accepted.
0 Likes
Message 6 of 7

ekinsb
Alumni
Alumni
Accepted solution

Here's an article I wrote a while ago about attributes that will hopefully help.  http://modthemachine.typepad.com/my_weblog/2009/07/introduction-to-attributes.html

 

 


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 7 of 7

danijel.radenkovic
Collaborator
Collaborator

Hello Mr. Ekins,

Thank you very much for the help. I understood and I will apply this usefull things on my projects.

 

Best regards

Danijel

 

 

 

Inventor 2018/Windows 10 x64
If this information was helpful, please consider marking it as an Accepted Solution by using the Accept as Solution. Kudos are also gladly accepted.
0 Likes