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: 

RunRule in assembly component does not run.

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
PappaJeff
235 Views, 5 Replies

RunRule in assembly component does not run.

I have a rule in an assembly component, Dome Panel Layout:1 that does run when the below code is run. I have tried it with the commented-out command as well. The code "Sketch Control " in the part works just fine. One interesting item that might be related is that if the "Sketch Control " in the part is run in the part, the results do not update in the assembly.

Thanks for the help.

 

Running Inventor 2021

 

 

Code from the assembly.

iLogicVb.RunRule("DOME PANEL LAYOUT:1", "SKETCH CONTROL")
'iLogicVb.UpdateWhenDone = True

 

 

Code from the part. While not elegant it works. 

Dim oDoc = ThisApplication.ActiveDocument

Dim oSketches As PlanarSketches = oDoc.ComponentDefinition.Sketches
For Each oSketch As PlanarSketch In oSketches

If COURSE_NUMBER = 1 Then
	If oSketch.Name = "DOME INSIDE PLATE SKETCH" Then
		oSketch.Visible = True
	End If 
End If
If COURSE_NUMBER = 1 Then	
	If	oSketch.Name = "DOME SECONDARY PLATE SKETCH" Then
		oSketch.Visible = False
	End If	
End If
If COURSE_NUMBER = 1 Then	
	If oSketch.Name = "DOME TERTIARY PLATE SKETCH" Then
		oSketch.Visible = False
	End If
End If
If COURSE_NUMBER = 1 Then	
	If oSketch.Name = "DOME QUAD PLATE SKETCH" Then
		oSketch.Visible = False
	End If
End If 


If COURSE_NUMBER = 2 Then
	If oSketch.Name = "DOME INSIDE PLATE SKETCH" Then
		oSketch.Visible = True
	End If 
End If
If COURSE_NUMBER = 2 Then	
	If	oSketch.Name = "DOME SECONDARY PLATE SKETCH" Then
		oSketch.Visible = True
	End If	
End If
If COURSE_NUMBER = 2 Then	
	If oSketch.Name = "DOME TERTIARY PLATE SKETCH" Then
		oSketch.Visible = False
	End If
End If
If COURSE_NUMBER = 2 Then	
	If oSketch.Name = "DOME QUAD PLATE SKETCH" Then
		oSketch.Visible = False
	End If
End If 


If COURSE_NUMBER = 3 Then
	If oSketch.Name = "DOME INSIDE PLATE SKETCH" Then
		oSketch.Visible = True
	End If 
End If
If COURSE_NUMBER = 3 Then	
	If	oSketch.Name = "DOME SECONDARY PLATE SKETCH" Then
		oSketch.Visible = True
	End If	
End If
If COURSE_NUMBER = 3 Then	
	If oSketch.Name = "DOME TERTIARY PLATE SKETCH" Then
		oSketch.Visible = True
	End If
End If
If COURSE_NUMBER = 3 Then	
	If oSketch.Name = "DOME QUAD PLATE SKETCH" Then
		oSketch.Visible = False
	End If
End If 

If COURSE_NUMBER = 4 Then
	If oSketch.Name = "DOME INSIDE PLATE SKETCH" Then
		oSketch.Visible = True
	End If 
End If
If COURSE_NUMBER = 4 Then	
	If	oSketch.Name = "DOME SECONDARY PLATE SKETCH" Then
		oSketch.Visible = True
	End If	
End If
If COURSE_NUMBER = 4 Then	
	If oSketch.Name = "DOME TERTIARY PLATE SKETCH" Then
		oSketch.Visible = True
	End If
End If
If COURSE_NUMBER = 4 Then	
	If oSketch.Name = "DOME QUAD PLATE SKETCH" Then
		oSketch.Visible = True
	End If
End If 



Next 
	

	


RuleParametersOutput ()
InventorVb.DocumentUpdate()
Parameter.UpdateAfterChange = True
iLogicVb.UpdateWhenDone = True

 

 

5 REPLIES 5
Message 2 of 6
WCrihfield
in reply to: PappaJeff

Hi @PappaJeff.  You will need to change the first line in your code that is within the part.  Change "ThisApplication.ActiveDocument" to "ThisDoc.Document" (both unquoted in the code).  The 'ActiveDocument' will be focusing on the main assembly, when it is called to run from there, instead of the part.  Using the 'ThisDoc.Document' terminology will fix it, so it focuses on the part, instead of the 'active' assembly.

Also, near the end, instead of:

InventorVb.DocumentUpdate()

...try re-using the variable you created in the first line, for the document, like this:

oDoc.Update2(True)

Also, those other two lines:

Parameter.UpdateAfterChange = True
iLogicVb.UpdateWhenDone = True

...are preparatory lines, so they are best used at, or near the start of the code, instead of at the end of it.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 6
WCrihfield
in reply to: PappaJeff

Hi @PappaJeff.  One other thing that may be helpful is to pay close attention to the DVRs (DesignViewRepresentations), both within the part document itself, and for the assembly component within the assembly that is representing that part.  Manually, to find these in the model browser tree...in an assembly, these are found under the Representations folder, then the category starting with "View" ; but in a part, there is no Representions folder, just the 'View' category.  If you do not have any 'custom' DVRs in the part (only the Master / [Primary] one), then it may not be important.  However, if you are using a custom one (DEFAULT or Default are two common custom ones), then you may need to make sure those changes to the visibility of those sketches got recorded by that custom DVR (DesignViewRepresentation) within the part document itself.  Then, once that is done, you may need to make sure the assembly component representing that part is set to the same DVR, and you may also want to make sure it is set to 'Associative'.  That associative setting ensures that it will stay up to date with what the model looks like, when visual changes happen to the model it represents.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 6
PappaJeff
in reply to: PappaJeff

Hello Wesley, 

The change you suggested updates the part file outside of the assembly only in that part file when opened is correct. The part file View Master is set to Master while assembly was set to Default.

I was getting ready to ask how to switch to Master when the program was run but I tried it on my own first. Added the code below and worked like a charm.

Thank you, Wesley, for your help today, I learned a lot. 

 

Jeff

ThisApplication.ActiveDocument.ComponentDefinition.RepresentationsManager.DesignViewRepresentations("Master").Activate

 

 

Message 5 of 6
PappaJeff
in reply to: PappaJeff

Hello Wesley,

I found that I also had to edit the part in the assembly and set the view representation for the part file to the correct representation view. I selected the associative check box as well. 

 

Thanks again Wesley.

 

 

Message 6 of 6
WCrihfield
in reply to: PappaJeff

Good to hear you got it figured out.

Also, just so you are aware, there is a way to check and set the DVR of an assembly component, within an assembly.  Just remember that when you set that assembly component to a specific DVR, that action is being recorded by the currently active DVR of the assembly that the component is currently in the context of.  Anyways, the ComponentOccurrence object has a property named "ActiveDesignViewRepresentation", which is ReadOnly (you can get its value, but can not set its value it directly), and returns a String (the name of the DVR).  Then there is also a ReadOnly property (ComponentOccurrence.IsAssociativeToDesignViewRepresentation) for checking if that DVR is associative or not, with a Boolean value.  Then it also has a method (Sub routine) specifically for setting that value (ComponentOccurrence.SetDesignViewRepresentation).  The first input it wants is the name of the DVR that is defined within the document that this component represents.  The second input is optional, and for future uses, so not used right now, you should not specify anything for it.  The third input is also optional, but is where you can specify that you want this DVR to be 'associative'.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report