Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
tjvz85
in reply to: Anonymous

Hi DanV,

 

Thanks for your response.

 

My goal is this:

We create new drawings for every part or assembly and we use the same template.

For parts, there will only be one sheet per drawing, but for assemblies, we add a sheet for a production specific partslist.

 

I would like to add the sheet for the assembly file that is on the first sheet.

I have code (written by Curtis Waguespack) to check the Views on the sheet to see whether a part or assembly has been placed and then call a specific function. But I wanted to see if I can rather just check the file placed in the drawing, determine whether it is a part or assembly, and then place the second sheet if it is an assembly.

 

The code below checks the views, if they are of an assembly, it checks if the model file has a Design view named colour and the writes the colour to a custom iproperty that I use in the title block. If we can't just verify whether the referenced file is an assembly, I would like to run through the views and place the sheet, based on existing Sheet Format.

 

Thank you in advance for your further assistance.

Sub Main 
	' Get the active drawing document. 
	Dim oDoc As DrawingDocument 
	oDoc = ThisApplication.ActiveDocument 
	
	Dim oSheet As Sheet
	oSheet = oDoc.ActiveSheet	
	
	Dim oViews As DrawingViews
	Dim oView As DrawingView
	

	'get the collection of view on the sheet
	oViews = oSheet.DrawingViews		
	
	' Iterate through the views on the sheet
	For Each oView In oViews	
		
		Dim docDesc As DocumentDescriptor 
		docDesc = oView.ReferencedDocumentDescriptor  
		
		' Verify that the drawing view is of an assembly. 
		If docDesc.ReferencedDocumentType <> kAssemblyDocumentObject Then 
			Continue For
		End If  
		
		' Get the component definition for the assembly. 
		Dim asmDef As AssemblyComponentDefinition 
		asmDef = docDesc.ReferencedDocument.ComponentDefinition 
		
		'define view rep collection
		Dim oViewReps As DesignViewRepresentations
		oViewReps = asmDef.RepresentationsManager.DesignViewRepresentations
		
		oColourViewRepFound = False
		For Each oViewRep In oViewReps
			If oViewRep.Name = "Colour" Then
				oColourViewRepFound = True 
			End If
		Next
		
		If oColourViewRepFound = True Then
			Call ProcessAssemblyColor(oView, asmDef.Occurrences) 
		End If
	Next

End Sub 



Private Sub ProcessAssemblyColor(drawView As DrawingView, _ 
                                 Occurrences As ComponentOccurrences) 
   ' Iterate through the current collection of occurrences. 
   Dim occ As ComponentOccurrence 
   For Each occ In Occurrences 
      ' Check to see if this occurrence is a part or assembly. 
      If occ.DefinitionDocumentType = kPartDocumentObject Then 

         ' Get the render style of the occurrence. 
         Dim color As RenderStyle 
         Dim sourceType As StyleSourceTypeEnum 
         color = occ.GetRenderStyle(sourceType)  
		If color.name IsNot Nothing Then
		 iProperties.Value("Custom", "Lackierung") = color.name
		 Exit For
	 	End If
			

      End If 
   Next 
End Sub