Inventor Customization

Reply
Distinguished Contributor
tdswanson
Posts: 137
Registered: ‎03-07-2012
Message 1 of 19 (850 Views)
Accepted Solution

Use VBA to Add Qty Req'd to Custom Properties for Components from the ****'y?

850 Views, 18 Replies
09-28-2012 09:04 AM

Hello:

 

I'd like to create a macro that I can run from within an assembly that will loop through each BOM item and add the quantity req'd to a custom property within the component.  I'm very familiar with VBA from Office, but I'm new to it with respect to Inventor so I'm pretty fuzzy with object titles and options.  Can someone assist with the coding?

 

Here's an outline of what I'd like to do:

 

Execute Macro from within Assembly file

 

For Each BOM Item to # of BOM Items

 

  If Vendor = "Make" then

    Set Component Custom Property "Qty_Reqd" = Total Qty from BOM

  Endif

 

Next BOM Item

 


Can someone help and/or Is there an easier way?

 

Thanks!!

********************************************************
Inventor 2014 64-bit SP1
Win 7 Pro 64-bit SP1
Mentor
MegaJerk
Posts: 266
Registered: ‎01-26-2011
Message 2 of 19 (847 Views)

Re: Use VBA to Add Qty Req'd to Custom Properties for Components from the ****'y

09-28-2012 09:53 AM in reply to: tdswanson

The below example is code that I use to look at each part in an assembly, tally up how many of each is being used, and throw that total into the Authority iProperty of each part. The only reason that I used a stock (vanilla) iProperty as the value holder is so I can more easily access it from the drawing where I need to display totals next to things like flat patterns, etc. etc.

However, if you don’t need to show these values on the drawings, then we’ll go with a custom iprop. Right now I’m just going to post the code that I have as I am at work. I also would like a little more information from you before I customize this to match your needs better. As it is, the code now looks for all parts that are able to be modified (IE: non-suppressed parts / non-library content center files), but you mention that you may have something in place that determines which parts you’ll be using (Vendor?). So are you using another iProperty, or are you too also just using what hasn’t been suppressed by a Level of Detail to determine which parts will actually be manufactured?

Once you provide that info I will be able to customize this for you, or you can set off to customizing it on your own. I know that a few posts back I helped someone with something similar, so if you click on my user name and look for my posts you might be able to find some other interesting information back there.

------------

 

Dim openDoc As Document
openDoc = ThisDoc.Document
Dim docFile As Document
If openDoc.DocumentType = 12291 Then    
For Each docFile In openDoc.AllReferencedDocuments
If docFile.IsModifiable = True Then
If docFile.DocumentType = 12290 Then
Dim assemblyDoc As AssemblyDocument
assemblyDoc = openDoc
Dim assemblyDef As AssemblyComponentDefinition
assemblyDef = assemblyDoc.ComponentDefinition
Dim partDoc As PartDocument
partDoc = ThisApplication.Documents.Open(docFile.FullFileName, False)
Dim partQty As ComponentOccurrencesEnumerator
partQty = assemblyDef.Occurrences.AllReferencedOccurrences(partDoc)
'MessageBox.Show(partQty.Count, "")
If IsNumeric(partQty.Count) = True Then
If CDblAny(partQty.Count) <>  CDblAny(iProperties.Value(docFile.DisplayName, "Project", "Authority")) Then
iProperties.Value(docFile.DisplayName, "Project", "Authority") = partQty.Count
partDoc.Close
Else 
partDoc.Close
End If 
End If 
Else 
Dim docDisplayName As String	
If docFile.LevelOfDetailName <> "Master" Then 
docDisplayName = (Left(docFile.DisplayName, Len(docFile.DisplayName) - Len(docFile.LevelOfDetailName) - 3))
'MessageBox.Show( (Left(docFile.DisplayName, Len(docFile.DisplayName) - Len(docFile.LevelOfDetailName) - 3)) ,"")
Else
docDisplayName = docFile.DisplayName
'MessageBox.Show(docFile.DisplayName,"")
End If 
If iProperties.Value(docDisplayname, "Project", "Authority") <> "Assembly" Then 
iProperties.Value( docDisplayName, "Project", "Authority") = "Assembly"
End If 
End If 
End If
Next
Else
MessageBox.Show("You must have a valid Assembly document open before using this code!", "File Type Mismatch!",MessageBoxButtons.OK,MessageBoxIcon.Exclamation)
End If 

 

--------------------------------------------------------------------------------------

If my solution seems to remedy your problem, please press the Accept Solution button, -
as it increases my power levels and will eventually help to elevate me towards outer space.

Check out my iLogic injection tool here : http://goo.gl/ce1Qg
--------------------------------------------------------------------------------------
Distinguished Contributor
tdswanson
Posts: 137
Registered: ‎03-07-2012
Message 3 of 19 (844 Views)

Re: Use VBA to Add Qty Req'd to Custom Properties for Components from the ****'y

09-28-2012 10:02 AM in reply to: MegaJerk

Thanks MegaJerk, your assertions are right on target. 

 

The end goal is to place "Quantity Req'd: X" on the print for the component without me having to manually do it.  I don't use the "Authority" field, so I guess I really don't care much about which particular field that we use to populate the data.

 

And yes, for custom components, I typically enter the word "Make" in the vendor field for the component model.  This will then differentiate the custom components in the parts lists on my assembly prints.

 

So I planned on using the Vendor field as a trigger point for the modification.  But your way looks to be more sophisticated, so that will probably work too.

 

Thanks very much for your help!  I'll paste your code in and run some tests and see how it goes.

********************************************************
Inventor 2014 64-bit SP1
Win 7 Pro 64-bit SP1
Distinguished Contributor
tdswanson
Posts: 137
Registered: ‎03-07-2012
Message 4 of 19 (840 Views)

Re: Use VBA to Add Qty Req'd to Custom Properties for Components from the ****'y

09-28-2012 10:18 AM in reply to: MegaJerk

Wait, is this VBA or iLogic?

 

It won't run in VBA.  I get errors in the first couple lines, the MessageBox command at the bottom is bad, and I need to change most of the variable setting steps to utilize the "Set" method. 

 

Am I missing something?

********************************************************
Inventor 2014 64-bit SP1
Win 7 Pro 64-bit SP1
Mentor
MegaJerk
Posts: 266
Registered: ‎01-26-2011
Message 5 of 19 (838 Views)

Re: Use VBA to Add Qty Req'd to Custom Properties for Components from the ****'y

09-28-2012 10:19 AM in reply to: tdswanson

iLogic

--------------------------------------------------------------------------------------

If my solution seems to remedy your problem, please press the Accept Solution button, -
as it increases my power levels and will eventually help to elevate me towards outer space.

Check out my iLogic injection tool here : http://goo.gl/ce1Qg
--------------------------------------------------------------------------------------
Distinguished Contributor
tdswanson
Posts: 137
Registered: ‎03-07-2012
Message 6 of 19 (836 Views)

Re: Use VBA to Add Qty Req'd to Custom Properties for Components from the ****'y

09-28-2012 10:21 AM in reply to: MegaJerk

Ahhh, well that explains it....  I'm even less experienced with this.  So I create a rule with this pasted in, right?  How do you trigger it?

********************************************************
Inventor 2014 64-bit SP1
Win 7 Pro 64-bit SP1
Distinguished Contributor
tdswanson
Posts: 137
Registered: ‎03-07-2012
Message 7 of 19 (832 Views)

Re: Use VBA to Add Qty Req'd to Custom Properties for Components from the ****'y

09-28-2012 10:27 AM in reply to: tdswanson

OK, so I've got that stuff figured out and I've got a rule created.  However, in my test assembly, it's getting hung up on a phantom sub-assembly created by the bolted joint wizard.

 

The error is:

 

*** iProperties: The component named "Bolted Connection" was not found.***

 

Can we filter out components that are phantom?

 

Thx

********************************************************
Inventor 2014 64-bit SP1
Win 7 Pro 64-bit SP1
Mentor
MegaJerk
Posts: 266
Registered: ‎01-26-2011
Message 8 of 19 (829 Views)

Re: Use VBA to Add Qty Req'd to Custom Properties for Components from the ****'y

09-28-2012 10:38 AM in reply to: MegaJerk

Ah! I’ve never messed with virtual components. If you’re using Inventor 2012 and happen to be able to post a small assembly that has everything needed, do so. Otherwise, when I get home I will mess around with recreating (and fixing) said error.

Darn! 

--------------------------------------------------------------------------------------

If my solution seems to remedy your problem, please press the Accept Solution button, -
as it increases my power levels and will eventually help to elevate me towards outer space.

Check out my iLogic injection tool here : http://goo.gl/ce1Qg
--------------------------------------------------------------------------------------
Distinguished Contributor
tdswanson
Posts: 137
Registered: ‎03-07-2012
Message 9 of 19 (827 Views)

Re: Use VBA to Add Qty Req'd to Custom Properties for Components from the ****'y

09-28-2012 10:41 AM in reply to: MegaJerk

Well I'm messing around a little myself with the iLogic code (my first time) and it looks pretty handy......

 

However, it looks like most of the fields that I would use to differentiate "make" parts for this code are unavailable to iLogic.  It doesn't look like I can choose the "BOM Structure" field or the "Vendor" field.  Am I wrong?

 

I'm using IV2012, but I really can't post my assembly because it's got customer proprietary stuff in it.  I'll see if I can get around to making up a test one with just some plates and a bolted joiint in it.

 

Thx!

********************************************************
Inventor 2014 64-bit SP1
Win 7 Pro 64-bit SP1
Distinguished Contributor
tdswanson
Posts: 137
Registered: ‎03-07-2012
Message 10 of 19 (808 Views)

Re: Use VBA to Add Qty Req'd to Custom Properties for Components from the ****'y

09-28-2012 01:36 PM in reply to: tdswanson

OK:

 

Here's a simple assembly with two flat plates and a bolted joint holding them together.  Same issue is present with the iLogic rule.  I'll be messing around a bit too over the weekend.

 

Thanks again for your help!

********************************************************
Inventor 2014 64-bit SP1
Win 7 Pro 64-bit SP1

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community


Inventor Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for Autodesk Inventor helps you achieve greater speed, accuracy, and automation from concept to manufacturing.

Connect with Inventor

Twitter

Facebook

Blogs

Pinterest

Youtube