Inventor Customization

Inventor Customization

Reply
Mentor
mslosar
Posts: 276
Registered: ‎08-11-2004
Message 1 of 16 (305 Views)
Accepted Solution

Searching whole assembly stack

305 Views, 15 Replies
09-18-2013 11:01 AM

I'm looking to write a VBA macro that'll run through an entire assembly and list all the assemblies and parts that have a custom property like "Inhouse" set to a certain value (YES/NO)...

 

Anyone able to point me at an example of something that at least runs through a whole assembly?

 

Thanks

This is from memory so you probably will have to do some digging in the API help.

----

Dim oTopDoc as Inventor.Document
Dim oDoc as Inventor.Document

Dim oPropSet As Inventor.PropertySet
Dim oProp As Inventor.Property
Dim sHold As String
Dim sFoundDocs as string

 

Set oTopDoc = ThisApplication.ActiveDocument

sFoundDocs = ""

 

For each oDoc in oTopDoc.AllReferencedDocuments
  Set oPropSet = oDoc.PropertySets("User Defined Properties")

  sHold = ""
  For Each oProp In oPropSet
    If oProp.Name = "InHouse" Then
      sHold = oProp.Value
      Exit For
    End If
  Next oProp

 

  If sHold <> "" then
    sFoundDocs = sFoundDocs & oDoc.FullFileName & vbcrlf
  End If

Next oDoc

 

msgbox sFoundDocs

Valued Mentor
Gruff
Posts: 440
Registered: ‎11-24-2003
Message 2 of 16 (289 Views)

Re: Searching whole assembly stack

09-18-2013 04:29 PM in reply to: mslosar

This is from memory so you probably will have to do some digging in the API help.

----

Dim oTopDoc as Inventor.Document
Dim oDoc as Inventor.Document

Dim oPropSet As Inventor.PropertySet
Dim oProp As Inventor.Property
Dim sHold As String
Dim sFoundDocs as string

 

Set oTopDoc = ThisApplication.ActiveDocument

sFoundDocs = ""

 

For each oDoc in oTopDoc.AllReferencedDocuments
  Set oPropSet = oDoc.PropertySets("User Defined Properties")

  sHold = ""
  For Each oProp In oPropSet
    If oProp.Name = "InHouse" Then
      sHold = oProp.Value
      Exit For
    End If
  Next oProp

 

  If sHold <> "" then
    sFoundDocs = sFoundDocs & oDoc.FullFileName & vbcrlf
  End If

Next oDoc

 

msgbox sFoundDocs

Mentor
mslosar
Posts: 276
Registered: ‎08-11-2004
Message 3 of 16 (275 Views)

Re: Searching whole assembly stack

09-19-2013 06:51 AM in reply to: Gruff
It's early so i'm not functioning at 100% yet :smileyhappy:

But, does "For each oDoc in oTopDoc.AllReferencedDocuments"
tell it to look at the entire assembly all the way down multiple sub-assembly levels? As in, look at everything used in this file?

Thank you for getting me to the starting line - if the above is true it's exactly what i'm after - thank you!
Mentor
pball
Posts: 265
Registered: ‎04-20-2012
Message 4 of 16 (270 Views)

Re: Searching whole assembly stack

09-19-2013 07:26 AM in reply to: mslosar

Yes the oTopDoc.AllReferencedDocuments will give all parts/assemblies from the main assembly and all sub-assemblies. There is only one possible draw back, which concernes derived parts.

 

If  you don't have any derived parts don't worry about this and even if you do it would only effect the script in certain circumstances. Lets say you have a left hand part and derived a right hand part. If you only have the right hand some where in the assembly you run this command on, when using .AllReferencedDocuments it will also include the left hand part.

 

I hope what I said doesn't confuse or alarm you, just want to give a heads up since i've run into the same thing before and it was an issue for me.

Mentor
mslosar
Posts: 276
Registered: ‎08-11-2004
Message 5 of 16 (266 Views)

Re: Searching whole assembly stack

09-19-2013 07:42 AM in reply to: pball

It's not alarming to me. We don't do much, if anything, with derived parts.

 

In essence, we're trying to develop a tool to allow us tag things for shipping location and then turn around a generate a report that says these pieces go here and these pieces go there, etc. If can made as simple as a field in a part/assembly that says ship: <pick location from pull down>, and then running the program to generate the report - it's a huge win.

Mentor
mslosar
Posts: 276
Registered: ‎08-11-2004
Message 6 of 16 (209 Views)

Re: Searching whole assembly stack

09-25-2013 08:51 AM in reply to: mslosar

I just ran the file on a quick dummied up assembly file.

Contents of file were two assemblies.
Assembly 1 had 3 parts with no tagged sub-pieces.
Assembly 2 had about 10 parts with 2 tagged sub-pieces.
Both top level assemblies were tagged.


My expectation was that the function would return the two tagged upper level assemblies and the two tagged lower level parts for a total of 4 pieces in the final message box.

Turns out it's because the sub-component files weren't in fact files, but virtual parts.

 

My guess is that while the virtual parts are seen, since the output is only listing fullfilename for each object found - there's not a filename for a virtual part. I'd need to get it to return something else, like the Description line.

Mentor
mslosar
Posts: 276
Registered: ‎08-11-2004
Message 7 of 16 (198 Views)

Re: Searching whole assembly stack

09-25-2013 09:53 AM in reply to: mslosar
Apparently this method doesn't work with virtual parts.

Is there a method that will work with virtual parts? We typically are using virtual parts for nuts/bolts/etc because adding a couple hundred bolts and couple hundred nuts to a model is something we like to avoid if possible.
Valued Mentor
Gruff
Posts: 440
Registered: ‎11-24-2003
Message 8 of 16 (190 Views)

Re: Searching whole assembly stack

09-25-2013 12:52 PM in reply to: mslosar

What is a virtual part?

Mentor
pball
Posts: 265
Registered: ‎04-20-2012
Message 9 of 16 (183 Views)

Re: Searching whole assembly stack

09-25-2013 01:19 PM in reply to: Gruff

Straight from wiki help.

 

The virtual component is a component that requires no modeling of geometry and no file. It is the equivalent to a custom part in a parts list.

Virtual components are considered and treated as real components for all practical purposes. They have a browser representation, have properties such as quantity, BOM Structure, Part Number, and so on.

 

 

You can create them using the create component command inside an assembly and ticking a check box on that dialog.

Valued Mentor
Gruff
Posts: 440
Registered: ‎11-24-2003
Message 10 of 16 (179 Views)

Re: Searching whole assembly stack

09-25-2013 01:23 PM in reply to: pball
Okay, I think I understand we do not use them here.
What about creating a temporary BOM that conatins your property.

Wouldn't that give you your list (With virtual parts)?
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.