Controlling Design View Representations on a Assembly using iLogic

Controlling Design View Representations on a Assembly using iLogic

RogerCamp
Advocate Advocate
3,107 Views
7 Replies
Message 1 of 8

Controlling Design View Representations on a Assembly using iLogic

RogerCamp
Advocate
Advocate

Hello folks!

I have the following scenario:

In my assembly, I have several Design View Representations, each one has a single part visible. This assembly has a form to select and switch to a specific Design View Representation.

What I need to do is, as I switch to that DVR (activated), it becomes unlocked and all the other ones are locked.

Can it be done? If so, does anybody have a code for that? Any help is much appreciated.

 

0 Likes
Accepted solutions (2)
3,108 Views
7 Replies
Replies (7)
Message 2 of 8

mcgyvr
Consultant
Consultant
Accepted solution

2 different codes..

One to lock... One to unlock..

Use/adapt as needed..

 'set a reference to the assembly component definintion.
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
'define view rep 
Dim oViewRep As DesignViewRepresentation

'record the active view rep name
Dim sActiveViewRep As String
sActiveViewRep = oAsmCompDef.RepresentationsManager.ActiveDesignViewRepresentation.Name

'Unlock the View Reps
For Each oViewRep In oAsmCompDef.RepresentationsManager.DesignViewRepresentations
'skip the master view rep
If  oViewRep.DesignViewType = DesignViewTypeEnum.kMasterDesignViewType Then 'do nothing
'skip any private view reps
ElseIf oViewRep.DesignViewType = DesignViewTypeEnum.kPrivateDesignViewType Then 'do nothing
ElseIf oViewRep.Name = sActiveViewRep Then 'do nothing
Else
'unlock the View Rep
	If oViewRep.locked = True Then
	oViewRep.locked = False
	End If
End If
Next







 'set a reference to the assembly component definintion.
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
'define view rep 
Dim oViewRep As DesignViewRepresentation

'record the active view rep name
Dim sActiveViewRep As String
sActiveViewRep = oAsmCompDef.RepresentationsManager.ActiveDesignViewRepresentation.Name

'Lock the View Reps
For Each oViewRep In oAsmCompDef.RepresentationsManager.DesignViewRepresentations
'skip the master view rep
If  oViewRep.DesignViewType = DesignViewTypeEnum.kMasterDesignViewType Then 'do nothing
'skip any private view reps
ElseIf oViewRep.DesignViewType = DesignViewTypeEnum.kPrivateDesignViewType Then 'do nothing
ElseIf oViewRep.Name = sActiveViewRep Then 'do nothing
Else
'Lock the View Rep
	If oViewRep.locked = False Then
	oViewRep.locked = True
	End If
End If
Next


-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
Message 3 of 8

RogerCamp
Advocate
Advocate

Thank you so much for your help.

I had to adapt the code, here's what I've got:

'record the active view rep name
Dim sActiveViewRep As String
sActiveViewRep = oAsmCompDef.RepresentationsManager.ActiveDesignViewRepresentation.Name

'Lock the View Reps
For Each oViewRep In oAsmCompDef.RepresentationsManager.DesignViewRepresentations
'skip the master view rep
If  oViewRep.DesignViewType = DesignViewTypeEnum.kMasterDesignViewType Then 'do nothing
'skip any private view reps
ElseIf oViewRep.DesignViewType = DesignViewTypeEnum.kPrivateDesignViewType Then 'do nothing
ElseIf oViewRep.Name = sActiveViewRep Then
Else
'Lock the View Rep
	If oViewRep.Locked = False Then
	oViewRep.Locked = True
	End If
End If
Next
oViewRep = oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item(sActiveViewRep) 
oViewRep.Locked = False

 

So, when I switch to the View Representation I want, the iLogic locks all of them leaving the active unlocked.

The only problem is that prior to the switch, I had the view to a certain part face in front (parallel to the screen), after switching back, the view is oriented to the Left. I have no clue why it's behaving like that. Do you know? 

0 Likes
Message 4 of 8

mcgyvr
Consultant
Consultant
Accepted solution

@RogerCamp wrote:

 

So, when I switch to the View Representation I want, the iLogic locks all of them leaving the active unlocked.

The only problem is that prior to the switch, I had the view to a certain part face in front (parallel to the screen), after switching back, the view is oriented to the Left. I have no clue why it's behaving like that. Do you know? 


Did you save to save the view (camera state I think its called)?

I have had some problems with what seems to be view rep camera states not being saved/stored but never tracked down to see if its a real problem or just a mistake I made or whatever..

 

If you have a reproducible case where its not seeming to work properly Autodesk may like that to troubleshoot it..



-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
Message 5 of 8

maximeURGVK
Enthusiast
Enthusiast
Message 6 of 8

RogerCamp
Advocate
Advocate

You're right, there's an option to save the view the way you want.

Thank you so much for your help. Awesome!

 

Untitled.png

0 Likes
Message 7 of 8

cleggett
Contributor
Contributor

This is exactly what I have been trying to accomplish!! I have been researching, and reading through Autodesk/API help materials and forums for about a week now! I knew I had to be getting close, but I just couldn't quite nail it down. I was going in circles, and could NOT figure out what the missing link was. 

 

The objective that I set out to accomplish was to have a rule that I could run, and have it cycle through my view reps and unlock them. Then be able to run it again or run a separate rule to cycle back through and lock them.  If not that, then to do basically what you have done here with these codes to lock and unlock the active view rep. 

If it's possible and if you are able to take some time and write up a rule that would accomplish the cycle through the view reps locking/ unlocking them I would appreciate that very much! I'd even buy you that beer! Lol if not then no big deal. I maybe can incorporate what you've provided here  into my original objective. I'm brand new to coding, and actually using ilogic. Im pretty experienced with inventor, but never really dove into the ilogic and programming side of inventor. Anyways, thanks for this code! 

Message 8 of 8

cleggett
Contributor
Contributor
I was able to adapt the code to accomplish similarly what someone up in the thread had already done, but here is the code. It loops through the design view reps and locks and unlocks all of them that isnt the active rep. I plan to use VB to create buttons on a ribbon panel to unlock and lock to make use of the codes


This locks them:

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
'define view rep
Dim oViewRep As DesignViewRepresentation

Dim sActiveViewRep As String
sActiveViewRep = oAsmCompDef.RepresentationsManager.ActiveDesignViewRepresentation.Name

For Each oViewRep In oAsmCompDef.RepresentationsManager.DesignViewRepresentations
If oViewRep.Name = sActiveViewRep Then
oViewRep.Locked = False
ElseIf oViewRep.DesignViewType = DesignViewTypeEnum.kPublicDesignViewType
If oViewRep.Name <> sActiveViewRep Then
End If
oViewRep.Locked = True
End If
Next




Unlocks:

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
'define view rep
Dim oViewRep As DesignViewRepresentation

Dim sActiveViewRep As String
sActiveViewRep = oAsmCompDef.RepresentationsManager.ActiveDesignViewRepresentation.Name

For Each oViewRep In oAsmCompDef.RepresentationsManager.DesignViewRepresentations
If oViewRep.Name = sActiveViewRep Then
oViewRep.Locked = False
ElseIf oViewRep.DesignViewType = DesignViewTypeEnum.kPublicDesignViewType
If oViewRep.Name <> sActiveViewRep Then
End If
oViewRep.Locked = False
End If
Next