Community
Inventor Forum
Welcome to Autodesk’s Inventor Forums. Share your knowledge, ask questions, and explore popular Inventor topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Cannot suppress pattern element using ilogic

33 REPLIES 33
SOLVED
Reply
Message 1 of 34
Olgan
6252 Views, 33 Replies

Cannot suppress pattern element using ilogic

I'm trying to use ilogic to suppress some individual elements of a pattern but i couldnt find any command that can target component pattern elements. When i try to capture its current state with the right click menu it does nothing.

I can of course suppress the part within the element but then it doesn't update the BOM.

 

Any comment or suggestion is appreciated

33 REPLIES 33
Message 2 of 34
Olgan
in reply to: Olgan

no one?

 

Message 3 of 34
Curtis_Waguespack
in reply to: Olgan

 

Hi Olgan,

 

Here is some example code that will suppress the 4th element of an assembly pattern named Component Pattern 1:1.

 

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

 

Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument

'reference the pattern in the assembly 
Dim oPattern As OccurrencePattern
oPattern = oDoc.ComponentDefinition.OccurrencePatterns.Item("Component Pattern 1:1") 'calls the pattern by name
'oPattern = oDoc.ComponentDefinition.OccurrencePatterns.Item(1) 'use this to call the pattern by item number

'suppress the 4th element
Dim oElement As OccurrencePatternElement
oPattern.OccurrencePatternElements.Item(4).Suppressed=True

 

Message 4 of 34
Olgan
in reply to: Curtis_Waguespack

thank you very much. did exactly what i wanted

 

Message 5 of 34
Kyle_of_Australia
in reply to: Olgan

I'm attempting a similar operation, but when I copy Curtis' code I get the following error:

 

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

(Note: Line 11 is the last line of the code.)

 

I'm pretty green when it comes to iLogic; I don't understand this error message (specifically what a method argument is).

 

Any help is appreciated!

Message 6 of 34

Sounds like you made a typo. Post the code you're using in a txt file.

Mike (not Matt) Rattray

Message 7 of 34

Greetings, distinguished mentor.

 

Funny thing is that I get the error message even if I do a straight copy/paste of Curtis' code above - without changing anything. I just went and tried it again, same deal.

 

But, just in case there's something really dumb I'm missing, I'll do what you ask.

Message 8 of 34
swordmaster
in reply to: Olgan

Look carefully at your code, you have two ? (questionmarks) . This is what is causing the problem.

This is a common problem with cutting/pasting code directly from posts.

 

Inventor 2010 Certified Professional
Message 9 of 34

Hi Swordmaster. Thanks for lookin' into my case. 

 

Very interesting with the question marks, I did not notice that before. However, they seem (to me at least) to have been produced by the copy from Inventor to Notepad, not the copy from this forum to Inventor. I am attaching a screenshot that shows the code in my rule editor. No visible question marks; still get the parentheses error.

 

=/

 

 

Message 10 of 34
Curtis_Waguespack
in reply to: Olgan

Hi Kyle_of_Australia,

 

In addition to the extra characters that swordmaster mentioned, the thing that I notice is that in the example code, the pattern that is being called is named "Component Pattern 1:1" , if you change that name to one of the named patterns in your assembly ("Outside Ctrack Pattern" for example) then I think you'll see it work. That is, if the named pattern has at least 4 elements, since the example is suppressing element 4.

 

Give this a shot and post back if you see still see errors.

 

Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument

'reference the pattern in the assembly 
Dim oPattern As OccurrencePattern 
'calls the pattern by name oPattern = oDoc.ComponentDefinition.OccurrencePatterns.Item("Outside Ctrack Pattern") 'suppress the 4th element Dim oElement As OccurrencePatternElement oPattern.OccurrencePatternElements.Item(4).Suppressed=True

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

Message 11 of 34

Hi Curtis! Thanks for your post. (Just Kyle's fine, btw.)

 

Yeah, changing the component pattern name was the first thing I did when I pasted your code initially. Funny thing is that Inventor does not seem to be picking up an error with that line; it's the last line of the code that keeps bringing up the error.

 

Even when I paste the code you just posted (and yep, currently that pattern has 4 elements), it still takes issue with the last line of the code. The error message is still "Error on Line 10 : Method arguments must be enclosed in parentheses."

 

Curiouser and curiouser.

Message 12 of 34

Hi Kyle,

 

Just a guess, but do you still see the error if you set your assembly to the Master LOD, and then run the rule?

 

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

Message 13 of 34

Hi again Curtis.

 

Nope, changing the LOD doesn't seem to fix it.

 

Hang on, I've just noticed some more information that might be helpful. I am now attaching a screenshot of both tabs of the error message.

Message 14 of 34

Hi Kyle,

 

The first warning is telling us that the following line is not needed.

 

Dim oElement As OccurrencePatternElement

 Indeed that line is just a vestige of whatever code I pulled the example from originally, and could be removed.

 

The second warning indicates that there is still an extra character in the last line, specifically in the word "suppressed". You might just retype it, but the problem is between the two S characters, for example: suppres_sed

 

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

Message 15 of 34

Success! It's now working.

 

Swordmaster was on to it. Although there was no visible error in the code, wherever the '?' appeared when I copied it to a text file, there was an issue.

 

The solution was to delete and retype those parts of the code, as suggested by Curtis.

 

Thanks to everyone who helped.

 

Now all I need to do is figure out how to unsuppress the elements when I change the parameter ("4" in Curits' example, but a user parameter called "Elongated_Ctrack_Location" in mine). If there's an easy way, I'd love to know, otherwise I'll have a play next time I've allow myself some Inventor playtime.

 

 

Message 16 of 34

Just change Suppressed = True to Suppressed = False. You can assign the True/False to a variable and use an If Then block to toggle the value of the variable and therefore the state of suppression.

 

So, something like:

 

Dim status As Boolean

If someParameter > 5 Then
   status = True
Else
   status = False
End If

Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument

'reference the pattern in the assembly 
Dim oPattern As OccurrencePattern 
'calls the pattern by name
oPattern = oDoc.ComponentDefinition.OccurrencePatterns.Item("Outside Ctrack Pattern") 

'suppress the 4th element
Dim oElement As OccurrencePatternElement
oPattern.OccurrencePatternElements.Item(4).Suppressed=status

 

Mike (not Matt) Rattray

Message 17 of 34

Hi Mike.

Just having a good look over your suggestion. Either I've misunderstood what it's supposed to do (quite possible), or it won't quite solve my particular conundrum.

This is the rule as it is now:

DimoDocAsAssemblyDocumentoDoc=ThisApplication.ActiveDocumentDimoPatternAsOccurrencePatternoPattern=oDoc.ComponentDefinition.OccurrencePatterns.Item("Bracket Pattern")oPattern.OccurrencePatternElements.Item(Elongated_Ctrack_Posn).Suppressed=True

So pretty much where we got up to with Curtis before, except instead of defining which occurrence to suppress with a numeral in the code, it pulls a value from a user parameter (Elongated_C-track_Posn), which the user will change from job to job.

Problem is, when that parameter is changed, all occurrences previously suppressed by this rule remain suppressed, and I want them to be unsuppressed when I change that value.

What I basically want is something like:

oPattern.OccurrencePatternElements.Item(<>Elongated_Ctrack_Posn).Suppressed=False

But that's not how you do it and I probably just made a few people cringe with my bad code.

Sorry if your previous suggestion actually covers this and I'm just too out of my depth to understand it.

Thanks,

Kyle

 

Message 18 of 34

Try this just before you suppress your specific instance:

 

For Each oElement In oPattern
    oElement.Suppressed = True
Next

 

Here it is inserted into the code I posted before:

 

Dim status As Boolean

If someParameter > 5 Then
   status = True
Else
   status = False
End If

Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument

'reference the pattern in the assembly 
Dim oPattern As OccurrencePattern 
'calls the pattern by name
oPattern = oDoc.ComponentDefinition.OccurrencePatterns.Item("Outside Ctrack Pattern") 

'suppress the 4th element
Dim oElement As OccurrencePatternElement
For Each oElement In oPattern
    oElement.Suppressed = True
Next
oPattern.OccurrencePatternElements.Item(Elongated_Ctrack_Posn).Suppressed=status

 

 

I didn't have time to test this, so if it doesn't work just post back.

 

Mike (not Matt) Rattray

Message 19 of 34

Hey Mike, thanks for replying again.

 

That code looks like it should do what I want (though it looks to me like the 'for each' line should be False, not true?), but I get a rule compile error. It says:

 

"Rule Compile Errors in Elongated Support Suppression, in Catenary System.iam

Error on Line 9 : Expression is of type 'Inventor.OccurrencePattern', which is not a collection type."

 

(Line 9 is the new line of code that you suggested.)

 

Here is what my code looks like now:

DimoDocAsAssemblyDocumentoDoc=ThisApplication.ActiveDocumentDimoPatternAsOccurrencePatternoPattern=oDoc.ComponentDefinition.OccurrencePatterns.Item("Bracket Pattern")ForEachoElementInoPatternoElement.Suppressed=TrueNextoPattern.OccurrencePatternElements.Item(Elongated_Ctrack_Posn).Suppressed=True

Thanks for the help again. I think all this is helping me understand ilogic a little better.

 

-Kyle

 

Message 20 of 34

Try this. I actually bothered to test it this time. Smiley Happy

 

Dim oDoc As AssemblyDocument
Dim oPattern As OccurrencePattern
Dim oElements As OccurrencePatternElements 
Dim oElement As OccurrencePatternElement

oDoc = ThisApplication.ActiveDocument
oPattern = oDoc.ComponentDefinition.OccurrencePatterns.Item("Bracket Pattern")
oElements = oPattern.OccurrencePatternElements

For Each oElement In oElements
    oElement.Suppressed = False
Next

oPattern.OccurrencePatternElements.Item(Elongated_Ctrack_Posn).Suppressed=True

 

Mike (not Matt) Rattray

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

Post to forums  

Autodesk Design & Make Report