Create View (Design Representation) for each body part

Create View (Design Representation) for each body part

ngdnam88
Advocate Advocate
854 Views
6 Replies
Message 1 of 7

Create View (Design Representation) for each body part

ngdnam88
Advocate
Advocate

Dears,
I'm trying make drawing view for all bodies. Please help me code that can create each view (Design Representation) for each solid body like that

ngnam1988_0-1690433683149.png

Thanks you!

0 Likes
Accepted solutions (1)
855 Views
6 Replies
Replies (6)
Message 2 of 7

WCrihfield
Mentor
Mentor
Accepted solution

Hi @ngdnam88.  I believe there are multiple ways to do this, but here is some fairly logical API code you could use in an iLogic rule for that task.

Sub Main
	If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kPartDocumentObject Then
		MsgBox("A Part Document must be active for this rule to work. Exiting.", vbCritical, "")
		Exit Sub
	End If
	Dim oPDoc As PartDocument = ThisDoc.Document
	Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
	If oPDef.HasMultipleSolidBodies = False Then Exit Sub
	Dim oBodies As SurfaceBodies = oPDef.SurfaceBodies
	Dim oRepsMgr As RepresentationsManager = oPDef.RepresentationsManager
	Dim oDVRs As DesignViewRepresentations = oRepsMgr.DesignViewRepresentations
	Dim oADVR As DesignViewRepresentation = oRepsMgr.ActiveDesignViewRepresentation
	For Each oBody As SurfaceBody In oBodies
		Dim oBodyDVR As DesignViewRepresentation = Nothing
		Try
			oBodyDVR = oDVRs.Item(oBody.Name)
		Catch
			oBodyDVR = oDVRs.Add(oBody.Name)
		End Try
		oBodyDVR.Activate
		oBody.Visible = True
		For Each oB As SurfaceBody In oBodies
			If oB IsNot oBody Then oB.Visible = False
		Next 'oB
	Next 'oBody
	Try : oADVR.Activate : Catch : End Try
End Sub

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 7

WCrihfield
Mentor
Mentor

Here are some other commands that could be used in situations like this:

To use this first one, you would first either pre-select one or more SurfaceBody objects, or add one or more of them to the active document's 'SelectSet', either by using SelectSet.Select (one at a time), or SelectSet.SelectMultiple (ObjectCollection).  Then execute this command to toggle their visibility.

 

ThisApplication.CommandManager.ControlDefinitions.Item("PartVisibilityCtxCmd").Execute

 

These other two commands are fairly self explanatory.

 

ThisApplication.CommandManager.ControlDefinitions.Item("HideOtherBodiesCtxCmd").Execute
ThisApplication.CommandManager.ControlDefinitions.Item("ShowAllBodiesCtxCmd").Execute

 

Edit:  Just in case you had not noticed yet, these three commands are essentially the same ones you see in your right mouse button click menu, when you have a solid body selected in the model browser tree.

WCrihfield_0-1690460276082.png

 

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 7

ngdnam88
Advocate
Advocate

Thanks @WCrihfield 
I got them. I learnt too much from you!

0 Likes
Message 5 of 7

ngdnam88
Advocate
Advocate

Hi @WCrihfield 
I'm trying controlling DVR. Could you help me some guide about its?

ngnam1988_0-1690686284473.png

ngnam1988_2-1690686318407.png

Thanks!

 

 

0 Likes
Message 6 of 7

WCrihfield
Mentor
Mentor

Hi @ngdnam88.  Hope you had a good weekend.  Yes, all those settings are accessible by code also.  I will post a few links to the related online API help documentation, and also a simple code example.  In the code example, I have the option you have chosen in the image uncommented, and have the alternative settings commented (greyed out), just so you can see all the possibilities.

RepresentationsManager 

RepresentationsManager.ActiveDesignViewRepresentation 

DesignViewRepresentation 

DesignViewRepresentation.AutoSaveCamera 

DesignViewRepresentation.SaveCurrentCamera 

DesignViewRepresentation.RestoreCamera 

DesignViewRepresentation.ModelAnnotationAutoScale 

DesignViewRepresentation.ModelAnnotationScale 

Dim oPDoc As PartDocument = ThisDoc.Document
Dim oRepMgr As RepresentationsManager = oPDoc.ComponentDefinition.RepresentationsManager
Dim ADVR As DesignViewRepresentation = oRepMgr.ActiveDesignViewRepresentation
ADVR.AutoSaveCamera = True
'both of these next two lines are Sub methods (do something, without returning anything)
'ADVR.SaveCurrentCamera
'ADVR.RestoreCamera

ADVR.ModelAnnotationAutoScale = True
'ADVR.ModelAnnotationScale = 40.06

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 7 of 7

ngdnam88
Advocate
Advocate

Thank you very much @WCrihfield 
I got them!

0 Likes