iLogic to control LoD in sub-assemblies

iLogic to control LoD in sub-assemblies

Anonymous
Not applicable
4,391 Views
25 Replies
Message 1 of 26

iLogic to control LoD in sub-assemblies

Anonymous
Not applicable

good morning All!

 

I've searched through the forum for an answer to this problem and found nothing I could use. I started "driving" my top level assembly (made up of sub assemblies) to control the length, height, width and style of my model.(in this case, the model is an alum. dump trailer. Everything was working fine until I began to place different model sides and another Tailgate model into the top level assembly to cover all the options. Now the problem occurs when I use the form to alter the models configuration for other options. What is happening is my sub assemblies (some, not all) revert to "Master" LoD which prevents the model from updating to the new configuration until I select the offending sub assembly and reset it to "Custom" LoD. So is there a way in my top level assembly iLogic rule to make sure all the sub assemblies including the ones I haven't placed ( I have 2 more side configurations for a total of 4 files yet to place) either stay at or reset to "Custom" LoD as I use the form to alter the models configuration?

   I have a couple of videos posted here as "screen casts" that show what I trying to do. I even recorded a peak at some of the iLogic code that drives the models.

   Thanks again for your time and assistance. Hope you all have a great day.

 

Frank

Inventor 2016

0 Likes
Accepted solutions (1)
4,392 Views
25 Replies
Replies (25)
Message 2 of 26

NSBowser
Advocate
Advocate

Frank,

 

You should be able to use the 'Link Level of Details' option under the 'Productivity' menu in the assembly to keep all the LOD's aligned. The LOD's just need to have the same name everywhere, including in the Top Level Assembly.

Give a try and let us know if that does what you need.


Best of Luck

---------------------------------------------------------------------------------------------------------------------------------
If you find this reply helpful or insightful, please use the 'Accept as Solution' or 'Kudos' button below.
Message 3 of 26

Anonymous
Not applicable

NSBowser,

 

I appreciate the suggestion, but it has no effect. As I  run the form and switch between the different options, it seems the sub assemblies reset to "Master" LoD. The other strange thing is that sometimes I get an error message about the LoD and other times the option change happens ok, but the sub assemblies have reverted to the "Master" LoD. Still searching for a solution.

 

Frank

Product Design Suite Ultimate 2016 

0 Likes
Message 4 of 26

NSBowser
Advocate
Advocate

Ok, if the linked LOD's arn't working you can try programmatically setting each documents LOD as needed, it would look something like the following.

 

oAssyDoc.ComponentDefinition.RepresentationsManager.LevelofDetailRepresentations("Custom").Activate

Best of Luck

---------------------------------------------------------------------------------------------------------------------------------
If you find this reply helpful or insightful, please use the 'Accept as Solution' or 'Kudos' button below.
Message 5 of 26

Anonymous
Not applicable

NSBowser,

 

Thanks for the effort, I copy / pasted your code into my top level assembly rule but I got the following error messages.

 

Error on Line 2 : 'oAssyDoc' is not declared. It may be inaccessible due to its protection level.
Error on Line 2 : Method arguments must be enclosed in parentheses.
Error on Line 2 : 'r' is not declared. It may be inaccessible due to its protection level.

 

Not sure why. I'm not at all up on this syntax. I use the snippets built into iLogic. At least I can follow it. 🙂  the VB stuff a lot of you guys use is Greek to me.

I'm just starting to get a handle on the stuff that is built into iLogic so trying to learn another code syntax is more than I want to tackle at the moment.

Got any stock iLogic code that will make the "custom" LoD active as the rule runs. The problem is that as I toggle between the different options in my top level assembly, from the iLogic form, different sub assemblies are resetting to "Master" LoD which causes problems as the rule runs.

 

Thanks again for your assistance.

 

Frank

Inventor 2016

0 Likes
Message 6 of 26

waynehelley
Collaborator
Collaborator

Hi Frank,

 

This should work...

 

ThisDoc.Document.ComponentDefinition.RepresentationsManager.LevelOfDetailRepresentations.Item("Custom").Activate()

 

Although all that line of code is doing is setting the LOD in the current document to "Custom".  This won't drill down through all the sub-assemblies and set their LOD to "Custom".  You would have to do something along the lines of a 'For' loop to achieve this.  You shouldn't need to do this though.

 

LOD behaviour is a bit tricky to explain but I will try.  I have an assembly which has 4 levels (i.e. top level, sub-assembly level 1, sub-assembly level 2, parts.  I open up each assembly and ensure each sub-assembly has a LOD called "Custom".

 

To get things working properly, I need to work my way upwards.  I will go into each sub-assembly level 1 assembly, make sure that my "Custom" LOD is selected then change each of my sub assembly level 2 assemblies so that their representations are set to "Custom".  Then I will save my level 1 assembly.  From now on, whenever I put my sub assembly level 1 assemblies into another assembly (i.e. my top level assembly) and change their representations to "Custom", the level 2 sub-assemblies should also change to "Custom".  This is because when I saved each of my level 1 sub-assemblies, the LOD states within it were saved too.

 

You should be able to do this automatously with 'Link Levels of Details' but I have had trouble with this too so I have just stuck to doing it manually.

Wayne Helley
Inventor 2013 Certified Professional

Autodesk Inventor Professional 2023
Visual Studio 2022
Windows 10 Pro, 64-bit
0 Likes
Message 7 of 26

waynehelley
Collaborator
Collaborator

I have actually just tried the 'Link Level of Details' tool and it has worked perfect for me.

 

I would try your best to get this working before you frazzle your brain trying to do things in iLogic.  Maybe just create a test assembly in order to try gain and understanding of exactly how its working.  You would be able to do it without actually putting any parts in it.

Wayne Helley
Inventor 2013 Certified Professional

Autodesk Inventor Professional 2023
Visual Studio 2022
Windows 10 Pro, 64-bit
0 Likes
Message 8 of 26

Jef_E
Collaborator
Collaborator

This is entirely off topic, but i'm gonna write it anyway.. and after my gibberish there is a possible solution.

 

iLogic = VB.NET

 

You can't write a descent tool and just say I don't want to tackle VB.NET as i'm only using iLogic. iLogic is VB.NET based, and the snippets are predefined methods or functions that could also be written by you. There is nothing facy about it.

 

You should really learn how to implement a descent bit of code using the API and then you can combine it with the iLogic keywords as you like.

 

 

For example the code supplied by @NSBowser

This code will work but it won't just go with copy/paste as you try to do so. Always read it before pasting, thats the key!

 

oAssyDoc.ComponentDefinition.RepresentationsManager.LevelofDetailRepresentations("Custom").Activate

 

 

 

When you want to use this code you can see the first bit is oAssyDoc this represent the AssemblyDocument Object and should be written like this.

 

 

Dim oAssyDoc As AssemblyDocument
???????

oAssyDoc.ComponentDefinition.RepresentationsManager.LevelofDetailRepresentation("Custom").Activate

Now you still need to say what assembly document you want to edit. Here you can use an iLogic snippit to say ThisDoc and it will reference the currently active document

 

Dim oAssyDoc As AssemblyDocument
oAssyDoc = ThisDoc

oAssyDoc.ComponentDefinition.RepresentationsManager.LevelofDetailRepresentation("Custom").Activate

 

Now while trying to explain to you how to implement given bits of codes by other users, rather than copy and pasting, it occurred to me that this piece of code is not really what you were asking.

 

So assuming that you have properly named the sub-assemblies to reference them by code, this solution will allow you to set the level of detail for each sub-assembly at the same time.

 

The code: only 8 lines and the rest is comments to explain Smiley Wink

' Set reference to the active document
Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument

' Set reference to the active document it's component definition.
Dim oDef As AssemblyComponentDefinition
oDef = oDoc.ComponentDefinition

' Create an array with the simple initialization syntax.
' So you can edit these names and add/remove if required
' This list can hold as many sub-assemblies as you like.
Dim oSubAssyList() As String = {"front", "rear", "bottom"}

' Loop through all the names in the array you just entered above and process
' All the subassemblies with the same code
For Each oSubAssy As String In oSubAssyList
    oDef.Occurrences.ItemByName(oSubAssy).SetLevelOfDetailRepresentation("Master", False)
Next

If you like I can explain the code some more how it works (if you are interested).

 

 



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
Message 9 of 26

Anonymous
Not applicable

Jeff,

   Sorry it has taken me so long to get back to your reply. I was on vacation this past week. I can't tell all you guys how much I appreciate all the help I get on this forum. I still have some replies to my question I have to sort through and I just got a call so I must switch modes for now, but I will return shortly with comments and kudos.

 

Frank Inventor 2016

0 Likes
Message 10 of 26

Anonymous
Not applicable

@Jef_E wrote:

This is entirely off topic, but i'm gonna write it anyway.. and after my gibberish there is a possible solution.

 

iLogic = VB.NET

 

You can't write a descent tool and just say I don't want to tackle VB.NET as i'm only using iLogic. iLogic is VB.NET based, and the snippets are predefined methods or functions that could also be written by you. There is nothing facy about it.

 

You should really learn how to implement a descent bit of code using the API and then you can combine it with the iLogic keywords as you like.

 

 

For example the code supplied by @NSBowser

This code will work but it won't just go with copy/paste as you try to do so. Always read it before pasting, thats the key!

 

oAssyDoc.ComponentDefinition.RepresentationsManager.LevelofDetailRepresentations("Custom").Activate

 

 

 

When you want to use this code you can see the first bit is oAssyDoc this represent the AssemblyDocument Object and should be written like this.

 

 

Dim oAssyDoc As AssemblyDocument
???????

oAssyDoc.ComponentDefinition.RepresentationsManager.LevelofDetailRepresentation("Custom").Activate

Now you still need to say what assembly document you want to edit. Here you can use an iLogic snippit to say ThisDoc and it will reference the currently active document

 

Dim oAssyDoc As AssemblyDocument
oAssyDoc = ThisDoc

oAssyDoc.ComponentDefinition.RepresentationsManager.LevelofDetailRepresentation("Custom").Activate

 

Now while trying to explain to you how to implement given bits of codes by other users, rather than copy and pasting, it occurred to me that this piece of code is not really what you were asking.

 

So assuming that you have properly named the sub-assemblies to reference them by code, this solution will allow you to set the level of detail for each sub-assembly at the same time.

 

The code: only 8 lines and the rest is comments to explain Smiley Wink

' Set reference to the active document
Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument

' Set reference to the active document it's component definition.
Dim oDef As AssemblyComponentDefinition
oDef = oDoc.ComponentDefinition

' Create an array with the simple initialization syntax.
' So you can edit these names and add/remove if required
' This list can hold as many sub-assemblies as you like.
Dim oSubAssyList() As String = {"front", "rear", "bottom"}

' Loop through all the names in the array you just entered above and process
' All the subassemblies with the same code
For Each oSubAssy As String In oSubAssyList
    oDef.Occurrences.ItemByName(oSubAssy).SetLevelOfDetailRepresentation("Master", False)
Next

If you like I can explain the code some more how it works (if you are interested).

 

 


Hi, Jeff. I'd like to know where you go to learn these things.

 

Now - when I place 

 

Dim oAssyDoc As AssemblyDocument

into my iLogic rule, I get:

 

Error on Line 2 : Type 'AssemblyDocument' is not defined.

0 Likes
Message 11 of 26

waynehelley
Collaborator
Collaborator

'Dim something As AssemblyDocument' doesn't work for me in the iLogic interface either.

 

Try getting rid of this line of code then everywhere in your code where you see 'oAssyDoc', replace it with 'ThisDoc.Document'

 

Basically what is happening here is...

 

Dim means Declare in Memory.  This basically means put aside a certain amount of RAM which I will use to hold information.  In this case were trying to create a 'container' called 'oAssyDoc' which is an object of the type 'AssemblyDocument'.  Since this type of container isn't available to use in iLogic, the code errors out.

 

Using 'ThisDoc.Document' instead of the container 'oAssyDoc' will just bypass the container and access the document directly.

 

For your question about where to learn this kind of stuff (if you are really serious about it), if you want to learn to code you are really better off giving VB.Net a try in Microsoft Visual Studio.  There are lots of great features in a 'real' programming interface which make it easier (once you get over the steep learning curve) to code and to learn about the Inventor API (API= a bunch of functions and objects which a programmer can use to manipulate a piece of software).  The iLogic interface isn't much more than a text editor with a few bolt-ons.

 

There is a tutorial I would recommend called something along the lines of 'My first Inventor Plug-In'.  You should be able to find it if you google it.

 

For any programmers reading this...

I'm not 100% on this but I think what iLogic calls 'ThisDoc' is actually an object of type 'ComponentOccurrence', hence if you want to access the 'Document' or 'AssemblyDocument' object, you need to be calling 'ThisDoc.Document'.

I just tested this theory: MsgBox(ThisDoc.FullDocumentName) will fail, MsgBox(ThisDoc.Document.FullDocumentName) will work.

 

Wayne Helley
Inventor 2013 Certified Professional

Autodesk Inventor Professional 2023
Visual Studio 2022
Windows 10 Pro, 64-bit
Message 12 of 26

Anonymous
Not applicable

Hi Wayne and thanks.

 

I guess my question should have been.

 

Where do you learn VB.net as it applies to Inventor? I can code algorithms till the cows come home. But accessing the guts of an inventor file - not so much.

 

Or where does one go to become an Inventor Certified Professional? If that's the same thing.

 

 

'============================

 

Ok, I found the SyntaxEditor Code Snippet

ThisDoc.Document

But how do I implement it? 

0 Likes
Message 13 of 26

waynehelley
Collaborator
Collaborator

That's a really difficult question to answer as there really isn't much learning material specific to the Inventor API.  Try that tutorial I mentioned, other than that I have just learnt by jumping in.  Learning how to use Visual Studio and about Object Oriented Programming in general will really help with your understanding of it.

 

The Certified Professional thing isn't really anything to do with the coding side of things.  Its just an Inventor exam.  I did it in 2013 back when there used to be days once a year when you could sit the exam for free.   I don't think they do this anymore and its about £150 to sit the exam at an Autodesk reseller I think.  Personally I'm not sure if I would bother... although my current employer did point out in my interview than he was quite impressed I had it so maybe it can be worthwhile.

Wayne Helley
Inventor 2013 Certified Professional

Autodesk Inventor Professional 2023
Visual Studio 2022
Windows 10 Pro, 64-bit
0 Likes
Message 14 of 26

Anonymous
Not applicable

Jef,

 

Sorry it took me so long to reply to your comment/suggestion. While I really do appreciate your efforts to help, your explanation is pretty much so much Greek to me. From your comments in you your code as to what I should do, it seems that you assume I understand what your comments are telling me to do. Sorry, I have no idea what they are referring to. I have zero experience with VB.NET programming. The syntax is so much gibberish to me. 🙂 I would need some quality time in a class for VB.NET programming to understand what you are talking about. I'm all for that except for the time it would take. I am being pushed to get this project done and just don't have the time. The snippets are doing what I need to get accomplished with my models (painfully) but it's working. Hopefully, at some future time I will be able to add the VB.NET tools to my skill set, but it won't be any time soon. Thanks again for all your comments. I really do appreciate them.

0 Likes
Message 15 of 26

NSBowser
Advocate
Advocate

Frank,

 

Your getting some bad information here, IMHO. I'm not sure where their getting their info, but AssemblyDocument is a perfectly valid and useful object type within the API, and works in iLogic without issue.

 

Here is a sample of code which employs the AssemblyDocument type and runs in iLogic... check it out for a good example of how to approach getting and validating your current document...

 

DO NOT use ThisDoc EVERYWHERE as indicated... ThisDoc could/should be called once, and then stored for later use... As shown in the code snippet below. Everytime you call ThisDoc the system has to re-evaluate it, which might sound like a small thing, but add that logic to EVERYTHING you code and it adds up, a lot.

 

 

Sub Main()

    Dim oDoc As Document
    oDoc = ThisDoc.Document
    
    Dim oAssyDoc As AssemblyDocument
    oAssyDoc = TryCast(oDoc, AssemblyDocument)
    
    If oAssyDoc Is Nothing Then
        MessageBox.Show("Document not of Assembly Type")
        Exit Sub
    End If
    
    MessageBox.Show("Document is of Assembly Type")
    ''' Rest of Code Goes here... '''
    
End Sub

 

There's a handful of ways you can approach this issue but I am partial to the one i have shown... you can also compare Document.Document type to a list of Enumerators, but then you have to either include the full enumeration information or convert it into an integer, both of which I personally dislike.

 

Sub Main()

	Dim oDoc As Document
	oDoc = ThisDoc.Document
	
	Select Case oDoc.DocumentType
		Case DocumentTypeEnum.kAssemblyDocumentObject
			MessageBox.Show("Document is Assembly Doc") ' BINGO
		Case DocumentTypeEnum.kDrawingDocumentObject
			MessageBox.Show("Document is Drawing Doc") ' this case could be removed
			Exit Sub
		Case DocumentTypeEnum.kPartDocumentObject' this case could be removed
			MessageBox.Show("Document is Part Doc")
			Exit Sub
		Case Else' this is the only other case you would need
			MessageBox.Show("Other")
			Exit Sub
	End Select
	
	Dim oAssyDoc As AssemblyDocument
	oAssyDoc =oDoc
		
	MessageBox.Show("Document is of Assembly Type")
	''' Rest of Code Goes here... '''
	
End Sub

Best of Luck

---------------------------------------------------------------------------------------------------------------------------------
If you find this reply helpful or insightful, please use the 'Accept as Solution' or 'Kudos' button below.
Message 16 of 26

NSBowser
Advocate
Advocate
Accepted solution

I feel i gave the second code snippet above an unfair shake by over complicating it.. Here is a revised version which attempts to follow the format/logic of the first more closely. Here you can see how similar the two are, i simply prefer the first

 

Sub Main()

	Dim oDoc As Document
	oDoc = ThisDoc.Document
 	
	If oDoc.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
		MessageBox.Show("Document not of Assembly Type")
		Exit Sub
	End If
	
	Dim oAssyDoc As AssemblyDocument
	oAssyDoc = oDoc
		
	MessageBox.Show("Document is of Assembly Type")
	''' Rest of Code Goes here... '''
	
End Sub

Best of Luck

---------------------------------------------------------------------------------------------------------------------------------
If you find this reply helpful or insightful, please use the 'Accept as Solution' or 'Kudos' button below.
Message 17 of 26

Anonymous
Not applicable

NSBowser,

 

    I think this is the point where I just accept this as the solution and stick to the built in snippets to work through my project. I'm getting totally frustrated with replies using VB.NET. I read the explanations and all I hear in my head is blah blah blah... 🙂 I know everybody is trying to be helpful and I appreciate it. But everything I've seen so far seems to based on the assumption that I understand VB.NET programming. I don't. Even the comments included in the code are useless to me. I feel like I'm sitting in on a conversation where everyone is speaking a language I don't speak. I've different types of programming over the years, but nothing similar to this as far as I can tell. So I'll just put myself out of my misery and accept your reply as a solution. Then keep my questions confined to snippet related solutions. Thanks again for trying.

 

 

Frank

Message 18 of 26

NSBowser
Advocate
Advocate

Frank,

 

I'm sorry to hear you are getting so frustrated. I can appreciate your struggle. As a non-programmer by trade, it has taken me 5 years of 'fiddling' to get to the level of competency I now enjoy. As such, it is my goal here to help teach people to fish, rather than hand out fish, solely based on the benefit they receive and the reward of personal development. I don't wish you to leave empty handed here, and am sorry that if this was something you had a greater priority/need for that we weren't able to help you quicker. As such, I've tried my hand at a program which SHOULD (crosses fingers) modify the design reps to custom for all assemblies within your main assembly. simply place this in the upper level rule and give it a try.

 

Sub Main()

    Dim oDoc As Document
    oDoc = ThisDoc.Document
    
    Dim oAssyDoc As AssemblyDocument
    oAssyDoc = TryCast(oDoc, AssemblyDocument)
    
    If oAssyDoc Is Nothing Then
        MessageBox.Show("Document not of Assembly Type")
        Exit Sub
    End If
    Try
		oAssyDoc.ComponentDefinition.RepresentationsManager.LevelofDetailRepresentations("Custom").Activate
	Catch
		MessageBox.Show("Unable to find 'Custom' LOD on " & oAssyDoc.DisplayName)
	End Try
	
	Dim oOccs As ComponentOccurrences
	oOccs = oAssyDoc.ComponentDefinition.Occurrences
	
	For Each oOcc As ComponentOccurrence In oOccs
		If oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject
			'MessageBox.Show(oOcc.Name)
			Try
				oOcc.SetLevelOfDetailRepresentation("Custom")
			Catch
				MessageBox.Show("Unable to find 'Custom' LOD on " & oOcc.Name)
			End Try
		End If
	Next
End Sub

 


Best of Luck

---------------------------------------------------------------------------------------------------------------------------------
If you find this reply helpful or insightful, please use the 'Accept as Solution' or 'Kudos' button below.
Message 19 of 26

NSBowser
Advocate
Advocate

I guess to add insult to injury... this problem has already been solved before, here.

 

http://forums.autodesk.com/t5/inventor-customization/change-lod-in-component/m-p/3452094/highlight/t...

 


Best of Luck

---------------------------------------------------------------------------------------------------------------------------------
If you find this reply helpful or insightful, please use the 'Accept as Solution' or 'Kudos' button below.
0 Likes
Message 20 of 26

waynehelley
Collaborator
Collaborator
Hi NSBowser,

'AssemblyDocument' definately wasn't working for me from within the iLogic interface earlier. Maybe it was because my code wasn't enclosed within a Sub Main()...End Sub

I didn't realise using objects (ThisDoc.Document) repeatedly without declaring in memory would have an effect on performance. Thanks for the tip
Wayne Helley
Inventor 2013 Certified Professional

Autodesk Inventor Professional 2023
Visual Studio 2022
Windows 10 Pro, 64-bit
0 Likes