Re: Ilogic Rule to find all Reference parts and turn off visibilty

Re: Ilogic Rule to find all Reference parts and turn off visibilty

steveh3
Advisor Advisor
635 Views
2 Replies
Message 1 of 3

Re: Ilogic Rule to find all Reference parts and turn off visibilty

steveh3
Advisor
Advisor

Hello Gang...almost exactly what I'm looking for.

I want to run same code but just on the active View Rep / Model State.

I messed around with code, but couldn't get it to go.

Possible?

Thanks in advance.

Steve Hilvers
Inventor Certified User / Vault Professional Influencer
0 Likes
Accepted solutions (1)
636 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor

Hi @steveh3.  I'm still using Inv 2021.2.2, so I don't currently have access to ModelStates, but since you only want the code to effect the 'current' view rep / model state, it doesn't seem like a problem to me, as long as they are not 'locked'.  I know that design view reps can be locked, and I know that model states have an 'edit member scope' setting to be aware of.  I am assuming that if a model state is currently active, it shouldn't be 'out of scope', but the scope may be set to 'all' or 'a specific set', so that is something I'm guessing you would need to keep in mind.  I also know that individual components within the assembly can be set to their own representations, and that they can be 'associatively' set to a view rep defined within them.  This setting may be a problem when attempting to change the visibility of the component.  I don't recall if it throws an error, or just breaks that 'associative' setting automatically to make the visibility change happen.

Have you tried something simple like this to see if it works?

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
	MsgBox("An Assembly Document must be active for this rule to work. Exiting.",vbCritical, "WRONG DOCUMENT TYPE")
	Exit Sub
End If
Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
'oVRep = oADef.RepresentationsManager.ActiveDesignViewRepresentation
'oMS = oADef.ModelStates.ActiveModelState
For Each oComp As ComponentOccurrence In oADef.Occurrences
	Try
		If oComp.BOMStructure = BOMStructureEnum.kReferenceBOMStructure Then
			'check if this component is associatively set to a view rep defined within itself
			'if so, then changing its visibility may 'break' this setting
			'If oComp.IsAssociativeToDesignViewRepresentation Then
			'	oComp.IsAssociativeToDesignViewRepresentation = False
			'End If
			oComp.Visible = False
		End If
	Catch e As Exception
		MsgBox(e.Message & vbCrLf & e.StackTrace, , "")
	End Try
Next

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 3

steveh3
Advisor
Advisor
Accepted solution

Gang...

Thanks for all the insight. So here's where I ended up and will share the logic....

 

Creates new View Rep and turns off all reference components at that level. Then activates the original View Rep when the iLogic was initiated....

 

' Creates a new View Rep "Active Components" and then turns all Reference Components visibility to off.
'It only turns On active Components at this level.
'Then returns back to original active View Rep when logic was initiated.



Dim odoc As Document
Dim oCompDef As ComponentDefinition
odoc = ThisApplication.ActiveDocument
oCompDef = odoc.ComponentDefinition


'Sets initial View Rep
oActiveViewRep = oCompDef.RepresentationsManager.ActiveDesignViewRepresentation



'Creates New View Rep
Dim oviewrep2 As DesignViewRepresentation
Try
oCompDef.RepresentationsManager.DesignViewRepresentations.Item("Active Components").Activate
Catch
 oviewrep2 = oCompDef.RepresentationsManager.DesignViewRepresentations.Add("Active Components")
End Try

'This turns off some object types in view rep
If odoc.DocumentType = kAssemblyDocumentObject Then
  ThisApplication.ActiveDocument.ObjectVisibility.WeldmentSymbols = False 
  'ThisApplication.ActiveDocument.ObjectVisibility.Welds = False
End If 



'This sets some parameters to turn off ref components 
oAssemblyComponents = oCompDef.Occurrences

Dim oOccurrence As ComponentOccurrence


    For Each oOccurrence In oAssemblyComponents
        If (oOccurrence.BOMStructure = BOMStructureEnum.kReferenceBOMStructure) Then
            oOccurrence.Visible = False
        Else
            oOccurrence.Visible = True
        End If
    Next

'Sets the view rep back to the one that was active before the rule was executed
oActiveViewRep.Activate 

 

Steve Hilvers
Inventor Certified User / Vault Professional Influencer
0 Likes