Run external rule in all top level subassemblies

Run external rule in all top level subassemblies

mat_hijs
Collaborator Collaborator
615 Views
2 Replies
Message 1 of 3

Run external rule in all top level subassemblies

mat_hijs
Collaborator
Collaborator

I've created an external rule "Export to RVT" which exports an assembly to RVT. This works perfectly. All the assemblies I want to eventually export to RVT are placed in one main assembly. So what I would like to do is either write some code which directly exports every top level subassembly to RVT. Or write some code that will run this external rule I have in every top level subassembly. Ideally it would go one step further and filter out subassemblies based on the filename or part number, for example only the ones that start with "V1_". I'm not really sure where to start on this one, but my end goal would be that I run one rule and all the necessary top level subassemblies will be exported to RVT.

Can anyone get me started on this?

 

The code in my external rule is this:

Dim oAsmDoc As AssemblyDocument
	oAsmDoc = ThisApplication.ActiveDocument

Dim oAsmCompDef As AssemblyComponentDefinition
	oAsmCompDef = oAsmDoc.ComponentDefinition

' Create RevitExportDefinition
Dim oRevitExportDef As RevitExportDefinition
	oRevitExportDef = oAsmCompDef.RevitExports.CreateDefinition
	
	oRevitExportDef.Location = "C:\Temp"
	oRevitExportDef.FileName = iProperties.Value("Project", "Part Number") & ".rvt"
	oRevitExportDef.ActiveDesignViewRepresentation = "Default"
	oRevitExportDef.IsAssociativeDesignView = True
	oRevitExportDef.Structure = kEachTopLevelComponentStructure
	oRevitExportDef.UseColorOverrideFromSourceComponent = False
	oRevitExportDef.EnableUpdating = False

' Create RevitExport.
Dim oRevitExport As RevitExport
	oRevitExport = oAsmDoc.ComponentDefinition.RevitExports.Add(oRevitExportDef)

0 Likes
Accepted solutions (1)
616 Views
2 Replies
Replies (2)
Message 2 of 3

theo.bot
Collaborator
Collaborator
Accepted solution

@mat_hijs  When you loop thru the Occurenses in a assembly you can call your external rule.

I have a small sample where you loop thru the Occurences and check if the referenced document is an assembly. I also capture the documents names in a list and check if a name already exsist in that list to avoid that you export multiple time the same assembly. I hope this get you started

 

Dim oDoc As AssemblyDocument
oDoc = ThisDoc.Document

Dim oCompdef As AssemblyComponentDefinition
oCompdef = oDoc.ComponentDefinition

Dim oFiles As New ArrayList

Dim oOcc As ComponentOccurrence

For Each oOcc In oCompdef.Occurrences
	
	'Get Document Referenced to Occurrence
	Dim oSubDoc As Document
	oSubDoc = oOcc.ReferencedDocumentDescriptor.ReferencedDocument
		
	If oSubDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
		
		'Check if the file is not already exported
		If oFiles.Contains(oSubDoc.FullFileName) = False Then
		oFiles.Add(oSubDoc.FullFileName)
		Logger.Info("Added to FileList: " & oSubDoc.FullFileName)
		
			'Additional checks
			'Add rule for Export
		Else
			Logger.Info( "File: " & oSubDoc.FullFileName & " Already exported ")
		End If

		
	Else
			Logger.Info(oOcc.Name & " is no Assembly")
	End If
'Run your Rule
Next

 

0 Likes
Message 3 of 3

mat_hijs
Collaborator
Collaborator

This seems to be exactly what I was looking for, thanks a lot!