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: 

EXPLODING PATTERNS WITH ILOGIC? HERE IT IS!

5 REPLIES 5
Reply
Message 1 of 6
LOONYLEN
1104 Views, 5 Replies

EXPLODING PATTERNS WITH ILOGIC? HERE IT IS!

Hello guys,

I was searching for a way to "explode" patterns using an iLogic rule.

I did some researching and came across an old post by Brian Ekins from 2008.

He had written some code to "explode" component patterns for the API.

I tweaked it a bit and got it to work inside of iLogic. It really works!

It's also very simple. Just a brief description of what the code does.

 

We start at element #2, because element #1 is the patterning component.

We count the number of elements in the pattern, then make them independent.

Making them independent, suppresses them in the pattern AND copies them to the design tree.

Then we simply delete the pattern sending the patterning component (element #1) into the design tree as well.

 

This code is in its basic form.

If you do not have the pattern that is named in the code, in your assembly, you will get an error.

I'm working on adding a "Don't run if you don't find the pattern" section to the code.

For now, you can use this as a starting point.

 

Code:

 

Sub Main() ExplodePattern
Dim oDoc As AssemblyDocument
 oDoc = ThisApplication.ActiveDocument
 
Dim oPattern As OccurrencePattern
 oPattern = oDoc.ComponentDefinition.OccurrencePatterns.Item("Component Pattern 1:1")
 
'MAKE EACH ELEMENT INDEPENDENT, STARTING AT THE SECOND ELEMENT.
Dim i As Integer
 'COUNT HOW MANY ELEMENTS ARE IN THE PATTERN, AFTER 2
 For i = 2 To oPattern.OccurrencePatternElements.Count
  'MAKE ALL ELEMENTS INDEPENDANT
  oPattern.OccurrencePatternElements.Item(i).Independent = True
  
 Next
'DELETE THE PATTERN, LEAVING ONLY THE INDEPENDENT COPIES AND THE ORIGINAL ELEMENT
oPattern.Delete
 End Sub

Senior Designer/Cad Administrator
Inventor 2012, w/SP2
Vault Collaboration 2012
Dell Precision T3500, Intel Xeon CPU
W3680 @3.33GHz, 16.0 GB of RAM
Microsoft Windows 7 Pro, 64 Bit Edition
Version 2009, w/SP1
5 REPLIES 5
Message 2 of 6
jdkriek
in reply to: LOONYLEN

iLogic simplified - no need for the Sub

 

oDoc = ThisDoc.Document
oPattern = oDoc.ComponentDefinition.OccurrencePatterns.Item("Component Pattern 1:1")
For i = 2 To oPattern.OccurrencePatternElements.count
	oPattern.OccurrencePatternElements.Item(i).Independent = True
Next
oPattern.Delete
Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


Message 3 of 6
8wr_zj
in reply to: jdkriek

jdkriek: thank you for providing this code to help us out exploding patterens. I tried to run this code with an assebly and i keep getting an error message.

 

The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

 

Any help would be great.

Inventor Pro 2014
nivida k6000
24 G RAM
Message 4 of 6
8wr_zj
in reply to: 8wr_zj

This is the code i am running i forgot to add it:

 

Format:HTML Format Version:1.0 StartHTML:     165 EndHTML:    3172 StartFragment:     314 EndFragment:    3140 StartSelection:     314 EndSelection:     314
SyntaxEditor Code Snippet

oDoc=ThisDoc.DocumentoPattern=oDoc.ComponentDefinition.OccurrencePatterns.Item("Componet Pattern 1:1")Fori=2TooPattern.OccurrencePatternElements.countoPattern.OccurrencePatternElements.Item(i).Independent=TrueNextoPattern.Delete
Inventor Pro 2014
nivida k6000
24 G RAM
Message 5 of 6
LOONYLEN
in reply to: 8wr_zj

8wr_zj,

 

First of all, you have spelled "Component" incorrectly in your code (Componet).

Also, have you replaced the "Component Pattern 1:1", with the name of your component pattern?

The name of your component pattern and the name in the code must match.

 

If this corrects your issue, please give Kudos and mark this answer as "Solution accepted".

 

Thanks,

 

Len

Senior Designer/Cad Administrator
Inventor 2012, w/SP2
Vault Collaboration 2012
Dell Precision T3500, Intel Xeon CPU
W3680 @3.33GHz, 16.0 GB of RAM
Microsoft Windows 7 Pro, 64 Bit Edition
Version 2009, w/SP1
Message 6 of 6
8wr_zj
in reply to: LOONYLEN

doh looks like fat fingered it.  Thank you for the help i got it to run great after i followed your direction.

Inventor Pro 2014
nivida k6000
24 G RAM

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

Post to forums  

Autodesk Design & Make Report