how to run part of my code an the aktive document only?

how to run part of my code an the aktive document only?

Darkforce_the_ilogic_guy
Advisor Advisor
179 Views
1 Reply
Message 1 of 2

how to run part of my code an the aktive document only?

Darkforce_the_ilogic_guy
Advisor
Advisor

how to run part of my code on the aktive document only?

 

Sub Main()
 
Dim doc = ThisApplication.ActiveDocument
Dim sDocumentSubType As String = doc.SubType
 
 
If sDocumentSubType = "{E60F81E1-49B3-11D0-93C3-7E0706000000}" Or sDocumentSubType = "{28EC8354-9024-440F-A8A2-0E0E55D635B0}" Then ' = "assembly"''
 
'I need this only to be run on the atkive Assembly
Assembly
 
End If
 
 
 
End Sub
 
 
 
 
Sub Assembly()
 
' my code
 
End Sub

 

 

0 Likes
180 Views
1 Reply
Reply (1)
Message 2 of 2

WCrihfield
Mentor
Mentor

Hi @Darkforce_the_ilogic_guy.  Here are some coding tips for if you only want to work on the 'active' document, and if you only want to work on a specific sub type of document.  There are several ways to do something like that.  It all depends on which way suits both your coding style and needs best.

 

Sub Main
	Dim oInvApp As Inventor.Application = ThisApplication
	Dim oADoc As Inventor.AssemblyDocument = TryCast(oInvApp.ActiveDocument, Inventor.AssemblyDocument)
	If oADoc Is Nothing Then
		'MessageBox.Show("An Assembly Document must be active when you run this rule.", "Wrong Document Type", MessageBoxButtons.OK, MessageBoxIcon.Stop)
		Logger.Debug("Rule named '" & iLogicVb.RuleName & "' did not run because no assembly obtained!")
		Return
	End If
	'only work on a Weldment type assembly
	If TypeOf oADoc.ComponentDefinition Is WeldmentComponentDefinition Then
		'your code here
	End If
	'another example of how to only work on a Weldment type assembly
	Dim sDocSubTypeName As String = oADoc.PropertySets.Item(3).Item(17).Value
	If sDocSubTypeName = "Weldment" Then
		'your code here
	End If
	'...your other code here
	'OtherRoutine(oADoc)
	'Dim oReturned = OtherFunction(oADoc)
End Sub

'Sub OtherRoutine(oDocToWorkOn As Inventor.Document) 'or (oADoc As Inventor.AssemblyDocument)
	
'End Sub

'Function OtherFunction(oDocToWorkOn As Inventor.Document) As WhatTypeFunctionShouldReturn
	
'End Function

 

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)

0 Likes