View Representations with iLogic: Error Object variable or With block variable not set.

View Representations with iLogic: Error Object variable or With block variable not set.

rogerJDLE5
Contributor Contributor
522 Views
3 Replies
Message 1 of 4

View Representations with iLogic: Error Object variable or With block variable not set.

rogerJDLE5
Contributor
Contributor

Hi,

 

I am relatively new to iLogic and am struggling with controlling view reps at assembly and at component level using iLogic rules in the assembly level document. I have searched the forum and API help and haven't quite found what I'm looking for. Hoping someone can shed some light on this for me...

 

Design intent:

Configure various view reps at assembly level to show a group of components in a steel crane girder that have specific component level view reps that are setup to show different states of fabrication. In this case one of the groups is a line of steel plates spliced together that forms the bottom flange of the girder. There are other rules that set the length, suppression and constraints of the plates. In the assembly level view rep, all of the individual bottom flange components must be in their default (fabricated) view rep, except the last component which needs to be in its "MATERIAL ORDER" view rep that shows the other side of a split used to hide/show the trim length allowed for in the component. 

 

I have tried a simple piece of code to trial the view rep based on one configuration only, but it kicks out the error: Object variable or With block variable not set.

rogerJDLE5_0-1622665606325.png

 

Below is the code I tried. Anyone able to see why I'm getting the error above?

 

' ********************
Dim
oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition Dim oOcc As ComponentOccurrence 'Activate a writeable View Rep (master view rep is not writeable) oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("BOTTOM FLANGE").Activate ' Set component View Rep oOcc.ItemByName("FLANGE_BOTTOM_#3:1").SetDesignViewRepresentation("Default",,) oOcc.ItemByName("FLANGE_BOTTOM_#4:1").SetDesignViewRepresentation("Default", , ) oOcc.ItemByName("FLANGE_BOTTOM_#5:1").SetDesignViewRepresentation("MATERIAL ORDER",,) ' ********************

 

0 Likes
Accepted solutions (1)
523 Views
3 Replies
Replies (3)
Message 2 of 4

A.Acheson
Mentor
Mentor
Accepted solution

Welcome to the forum, it is a lot like cracking a nut 🐿 Be persistent😂

View reps are tricky for sure. 

 

Just looking at the code the first thing that stands out is the variable oOcc hasn’t been set to a specific assembly.  
Next thing is you will need to loop through each occurrence in the assembly if you intend to set the view rep. Then in the loop, filter for the occurrence you want and then do something with it.

The snippet below sets the variable and loops at the same time.

For Each oOcc In oAsmCompDef.Occurrences

‘Filter......
If oOcc.Name =???
‘Do something......
Next

Post similar to your request and for sub assemblies


https://forums.autodesk.com/t5/inventor-customization/ilogic-sub-assembly-set-view-rep/td-p/7362982


Might be helpful.


https://forums.autodesk.com/t5/inventor-customization/ilogic-view-representation/td-p/4668063

 

Need anymore help, ask away!

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 4

Ralf_Krieg
Advisor
Advisor

Hello

 

You definie a variable oOcc but don't assign a value or object to it.

Try

' ********************
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
Dim oOccs as ComponentOccurrences= oAsmCompDef.Occurrences

'Activate a writeable View Rep (master view rep is not writeable)
oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("BOTTOM FLANGE").Activate

' Set component View Rep
oOccs.ItemByName("FLANGE_BOTTOM_#3:1").SetDesignViewRepresentation("Default",,)
oOccs.ItemByName("FLANGE_BOTTOM_#4:1").SetDesignViewRepresentation("Default", , )
oOccs.ItemByName("FLANGE_BOTTOM_#5:1").SetDesignViewRepresentation("MATERIAL ORDER",,)

' ********************

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
Message 4 of 4

rogerJDLE5
Contributor
Contributor

Hi @A.Acheson,

 

Thanks for the empathetic and helpful response! 

 

I have this initial trial piece of code now that seems to run well:

Dim doc As AssemblyDocument = ThisDoc.Document  
Dim oAsmCompDef As ComponentDefinition  
oAsmCompDef = doc.ComponentDefinition 
Dim oCompOcc As Inventor.ComponentOccurrence

'Activate a writeable View Rep (master view rep is not writeable)
oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("BOTTOM FLANGE").Activate

For Each oCompOcc In oAsmCompDef.Occurrences
'	Filter......
	If oCompOcc.Name = "FLANGE_BOTTOM_#2:1" And BF_LENGTH_3 = 0 Then
		oCompOcc.SetDesignViewRepresentation("MATERIAL ORDER", True)
		
	ElseIf oCompOcc.Name = "FLANGE_BOTTOM_#2:1" And BF_LENGTH_3 > 0 Then
		oCompOcc.SetDesignViewRepresentation("Default", True)
	
	ElseIf oCompOcc.Name = "FLANGE_BOTTOM_#3:1" And BF_LENGTH_4 = 0 Then
		oCompOcc.SetDesignViewRepresentation("MATERIAL ORDER", True)
	
	ElseIf oCompOcc.Name = "FLANGE_BOTTOM_#3:1" And BF_LENGTH_4 > 0 Then
		oCompOcc.SetDesignViewRepresentation("Default", True)
	
	ElseIf oCompOcc.Name = "FLANGE_BOTTOM_#4:1" And BF_LENGTH_5 = 0 Then
		oCompOcc.SetDesignViewRepresentation("MATERIAL ORDER", True)
	
	ElseIf oCompOcc.Name = "FLANGE_BOTTOM_#4:1" And BF_LENGTH_5 > 0 Then
		oCompOcc.SetDesignViewRepresentation("Default", True)		
	
	End If	
Next

ThisApplication.ActiveView.Fit