Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ILogic help needed!

41 REPLIES 41
SOLVED
Reply
Message 1 of 42
Infoseeker
5090 Views, 41 Replies

ILogic help needed!

Is it possible to have iLogic rule create parts lists out of View Representations?

 

http://forums.autodesk.com/t5/Autodesk-Inventor/View-representation-parts-list-error/m-p/3606706/hig...

41 REPLIES 41
Message 2 of 42
mcgyvr
in reply to: Infoseeker

tagging along..



-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
Message 3 of 42

Hi  Infoseeker,

 

If you are use the iLogic function IsActive to suppress component instances, their BOM structure is set to Reference. Therefore the suppressed occurrence, and only that occurrence will be removed from the BOM.

 

So IsActive not only suppresses the occurrence it also set's it's BOM structure as if you'd right clicked on it and selected BOM Structure > Reference. Recall that this is different that setting the BOM structure in the BOM editor or via the Document Settings, those 2 methods set it per file, rather than per assembly occurrence.

 

With this in mind here is an example rule. In this rule you select an item (on screen or in the browser, and it will be toggled on/off, and removed or added to the BOM. This is just a quick example to demonstrate the concept.

 

But to speak to the original request: I suspect you could use this idea to look at each occurrence in an assembly and check it's visibility setting (per the current Design View Representation) and then toggle the BOM structure for that occurrence to Reference if the occurrence is not visible.

 

I'm short on time, so I can't have a look at this anytime soon, but I thought I'd throw this out in case someone else wants to give it a shot.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

'set a reference to the assembly component definition.
'this assumes an assembly document is open.
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

'get currently selected component
Dim oOccurrence as ComponentOccurrence

Try
  oOccurrence = ThisDoc.Document.SelectSet.Item(1)
Catch
  MessageBox.Show("Please select a component before running this rule.", "iLogic")
  Return
End Try

'set the selected item
'oOccurrence = ThisApplication.ActiveDocument.SelectSet.Item(1)

'activate the Master LOD so we can read in the names of all the components
oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations("Master").Activate
InventorVb.DocumentUpdate(False)

'define an arraylist to hold the list of  LOD rep names
Dim NameList As New ArrayList()

'define LOD rep 
Dim oLODRep As LevelOfDetailRepresentation

'Look at the LOD reps in the assembly
For Each oLODRep In oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations
'set the list of names to the array list
NameList.add(oLODRep.Name)
Next

'check for an iLogic LOD rep and create it if not found
If Not NameList.Contains("iLogic LOD") Then
	'create iLogic LOD 
	oLODRep = oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Add("iLogic LOD") 
	oLODRep.Activate
Else 
oLODRep.Activate
End If

'Toggle the selected component's active status
If Component.IsActive(oOccurrence.Name) = True Then
Component.IsActive(oOccurrence.Name) = False
Else
Component.IsActive(oOccurrence.Name) = True
End If

'Save File (set LOD changes)
ThisDoc.Save

 

Message 4 of 42

I think it would be much more user friendly if we toggled the bom structure directly instead of using isactive. This way we needn't deal with any LOD headaches.

 

You can use these snippets to control the bom structure at the assembly level:

Component.InventorComponent("occurence").BOMStructure = BOMStructureEnum.kDefaultBOMStructure
Component.InventorComponent("occurence").BOMStructure = BOMStructureEnum.kReferenceBOMStructure

 

You could then use a loop to cycle through each occurence checking it's visibility setting per Curtis's suggestion and set it's bom structure accordingly.

 

 

Mike (not Matt) Rattray

Message 5 of 42

Hi mrattray,

I think you're spot on. And here's a snippet I had on hand, to iterate though the component occurrences of the assembly  in case it helps someone.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

' set a reference to the assembly component definintion.
' This assumes an assembly document is open.
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

'Iterate through all of the occurrences
Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oAsmCompDef.Occurrences
'check for and skip virtual components
'(in case a virtual component trips things up)
If Not TypeOf oOccurrence.Definition Is VirtualComponentDefinition Then
'Show occurrence name In the message box body
MessageBox.Show(oOccurrence.Name, "iLogic")
Else
End If
Next

 

Message 6 of 42

Hi Inventor users,

 

Here's the code snippets above combined into a rule that sets the BOM structure to Reference if the component is not visible.

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

' set a reference to the assembly component definintion.
' This assumes an assembly document is open.
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

'Iterate through all of the occurrences
Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oAsmCompDef.Occurrences
'check for and skip virtual components
If Not TypeOf oOccurrence.Definition Is VirtualComponentDefinition Then
	'set BOM as default if the component is visible
	If Component.Visible(oOccurrence.Name) = True Then
	Component.InventorComponent(oOccurrence.Name).BOMStructure = _
	BOMStructureEnum.kDefaultBOMStructure
	'set BOM as reference if the component is not visible
	ElseIf Component.Visible(oOccurrence.Name) = False Then
	Component.InventorComponent(oOccurrence.Name).BOMStructure = _
	BOMStructureEnum.kReferenceBOMStructure
	End If
Else
End If
Next

 

Message 7 of 42
Infoseeker
in reply to: Infoseeker

Awesome! Thanks.

This rule needs to be added to the .idw or .iam?

Message 8 of 42
Infoseeker
in reply to: Infoseeker

I guess assembly.

Message 9 of 42
Infoseeker
in reply to: Infoseeker

Does not work for me, maybe because I also use in my parts list substitute and grouping option... Or I am just missing something.

Message 10 of 42
mrattray
in reply to: Infoseeker

How does it not work? Is there an error message? Did you put it in the assembly?(it has no business being in the idw) Does it do something unexpected? We need more information than "it doesn't work" if we're going to be of any help to you. Can you post the files here?

Mike (not Matt) Rattray

Message 11 of 42
Infoseeker
in reply to: Infoseeker

Yes, I figured out it has no business to be in .idw file, as you can see in my previous post.

The rule has been added to the main assembly file, the one with View Reps that are used for parts lists generation.

I wrote it does not work, with no detailed description, because it just does not work: makes no difference if the rule is there or if is not. No warnings, pop ups, no nothing. No changes to Parts Lists display: total number of the parts is shown if only one out of few is visible in the view.

Does it work for you?

Message 12 of 42
Infoseeker
in reply to: Infoseeker

Anyone had a chance to test it?

 

Message 13 of 42
swordmaster
in reply to: Infoseeker

The code posted by Curtis, works as he descibed. I tested it in a simple assembly

changing a component to be not visible changes the BOM structure to Reference and vice versa

Are you sure the rule is being fired?

Inventor 2010 Certified Professional
Message 14 of 42
Infoseeker
in reply to: swordmaster

When I open standard template, the rule seems to work partially; it sets parts to reference parts but then BOM does not change when I turn visibility on and off.

 

The other thing is that my QTY comes from iproperty, that is connected to user parameters of a part, not actual number of parts in assembly. Then iproperty numbers are substituted for QTY. 

 

On the picture you can see that I have 3 parts out of 6 visible, BOM shows only 1, the rest is set to reference.

Message 15 of 42

I am using Inventor 2012 with 64 bit Windows 7.

I have the view representation assembly open.

Created the rule, cut and pasted the code.

I am getting the following Errors:

 

Rule Compile Errors in View_Rep_BOM, in 11-647-12.iam

Error on Line 13 : Method arguments must be enclosed in parentheses.

Error on Line 17 : Method arguments must be enclosed in parentheses.

 

I have tried putting brackets in, but cannot make it happy. Any help would be much appreciated.

Message 16 of 42
mrattray
in reply to: d_m_fleming

Sometimes copy/paste from this board scews up code. Nobody knows why. Copy your rule and paste into a txt file, post it, and I'll correct it.

Mike (not Matt) Rattray

Message 17 of 42
mrattray
in reply to: Infoseeker

If you're still workin on this, can you post your data set?

Mike (not Matt) Rattray

Message 18 of 42
d_m_fleming
in reply to: mrattray

Thanks.

Message 19 of 42
mrattray
in reply to: d_m_fleming

The code looks fine to me. Is that the entire contents of the rule, or do you have another section that you didn't include? You can try this copy, it's just reformated a little.

If that is the whole rule and the new copy doesn't work then can you post up the data set for me to investigate?

Mike (not Matt) Rattray

Message 20 of 42
d_m_fleming
in reply to: mrattray

Thanks Mike (not Matt)

That was the whole rule.

I don't see that you sent any copy for me.

I am not sure what you require when you ask for the data set.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report