error running rule in subassembly

error running rule in subassembly

GeertvanderHeide
Advocate Advocate
262 Views
3 Replies
Message 1 of 4

error running rule in subassembly

GeertvanderHeide
Advocate
Advocate

i have a rule where i run another rule in a subassembly that is in another subassembly. 

(main assembly: rule --> sub --> sub: rule)

everything seems to work fine when opening the sub and running the rule but i get an error when suppressing mates. 
previously i also got an error when using component.visible in the sub rule, so i replaced all the component.visible with a function:

Function Componentvisibility (Name As String, visibility As Boolean)
Dim doc As Document = ThisDoc.Document
Dim compdef As ComponentDefinition = doc.componentdefinition
For Each occ As ComponentOccurrence In compdef.Occurrences
	If occ.Name = Name Then
		occ.Visible = Visibility
		Exit For
	End If
Next
End Function

this works fine and solves all visibility issues i had.

so when i got an error when suppressing constraints with constraint.isactive is also created a function for that:

Function ConstraintIsActive(Name As String, State As Boolean)
Dim doc As Document = ThisDoc.Document
Dim compdef As ComponentDefinition = doc.componentdefinition
State = Not State
For Each cons As AssemblyConstraint In compdef.constraints
	If cons.Name = Name Then
		cons.Suppressed = State
		Exit For
	End If
Next
End Function

but this does not seem to fix the problem. everytime i get an error at line 7 (of the example)

 

it looks like constraints.isactive as well as cons.suppressed are write protected. 

The file is checked out/ not read-only.

The file is open visible.

when running the rule in the subassembly manually (not ran from another ilogic rule) i don't get any errors, so i assume it has something to do with the different assembly levels this code is excecuted.

 

are there any known erros/ solutions for this problem?

0 Likes
263 Views
3 Replies
Replies (3)
Message 2 of 4

WCrihfield
Mentor
Mentor

Hi @GeertvanderHeide.  Are there any custom ModelStates or any custom PositionalRepresentations present in that sub assembly?  If any custom ModelStates are present, then document reference may still be an issue (need to make sure you have reference to FactoryDocument version of it).  If custom PositionalRepresentations are present, they usually attempt to record things like constraint suppressions, constraint overrides, and such things, so you may have to check that situation.  Those are always 'fun' 🙄 to deal with by code, especially a couple steps down from the top.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 4

GeertvanderHeide
Advocate
Advocate

@WCrihfield  only thing i have active is the default view representation in stead of the master (which also may prevent view changes). there are no other model states or positions in the assembly. 

I did however find some strange behaviour.

When running the code manually in the lowest level i log the doc.ismodifiable property, which of course returns true. this is expected. 

But then i do it from the top level assembly, and the same sub, the same rule, nothing changed,, suddenly the ismodifiable property returns false.... 

then it makes sense that changes to mates will cause errors, but how is this possible? the file is still checked out, still open, and i should be able to change everything to it. what actions can cause this file to become read-only. and then again, alone from the top level, because if i open the sub and run rune the rule, well,, guess what....

0 Likes
Message 4 of 4

GeertvanderHeide
Advocate
Advocate

Update! 

when trying to run rules in subs the subassembly is not modifiable. 

However when all the actions are performed from a rule in the top level assembly the subassembly is modifiable.

does fix my problem for now, but seems to make the functionality of running rules in subs a bit useless...

0 Likes