Print only if custom iProperty is....

Print only if custom iProperty is....

joshdollahan
Explorer Explorer
336 Views
5 Replies
Message 1 of 6

Print only if custom iProperty is....

joshdollahan
Explorer
Explorer

I want to modify my Batch Print code, so that will only print if it has custom iproperty.....of say 4

iProperties.Value("Custom", "ACS OP#") = 4

 

here is my code

 

'define the active document as an assembly file
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
oAsmName = Left(oAsmDoc.DisplayName, Len(oAsmDoc.DisplayName) -4)


'check that the active document is an assembly file
If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then
MessageBox.Show("Please run this rule from the assembly file.", "iLogic")
Exit Sub
End If
'- - - - - - - - - - - - -Component Drawings - - - - - - - - - - - -'look at the files referenced by the assembly
Dim oRefDocs As DocumentsEnumerator
oRefDocs = oAsmDoc.AllReferencedDocuments
Dim oRefDoc As Document


'work the the drawing files for the referenced models'this expects that the model has a drawing of the same path and name 
For Each oRefDoc In oRefDocs
idwPathName = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentName) - 3) & "idw"
'check to see that the model has a drawing of the same path and name 
If(System.IO.File.Exists(idwPathName)) Then
                        Dim oDrawDoc As DrawingDocument
                oDrawDoc = ThisApplication.Documents.Open(idwPathName, True)
                oFileName = Left(oRefDoc.DisplayName, Len(oRefDoc.DisplayName) -3)
                
                Else
    
'If the model has no drawing of the same path and name - do nothing
End If
Next
'- - - - - - - - - - - - -

  

0 Likes
Accepted solutions (1)
337 Views
5 Replies
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor

Hi @joshdollahan.  Something like this maybe?

'check that the active document is an assembly file
If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then
	MessageBox.Show("Please run this rule from the assembly file.", "iLogic")
	Exit Sub
End If
'define the active document as an assembly file
Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
oAsmName = System.IO.Path.GetFileNameWithoutExtension(oAsmDoc.FullFileName)
'- - - - - - - - - - - - -Component Drawings - - - - - - - - - - - -'look at the files referenced by the assembly
Dim oRefDocs As DocumentsEnumerator = oAsmDoc.AllReferencedDocuments
Dim oRefDoc As Document
'work the the drawing files for the referenced models'this expects that the model has a drawing of the same path and name 
For Each oRefDoc In oRefDocs
	idwPathName = System.IO.Path.ChangeExtension(oRefDoc.FullFileName, ".idw")
	'check to see that the model has a drawing of the same path and name 
	If Not System.IO.File.Exists(idwPathName) Then Continue For
	Dim oDrawDoc As DrawingDocument = ThisApplication.Documents.Open(idwPathName, True)
	Dim oPMgr As DrawingPrintManager = oDrawDoc.PrintManager
	'oPMgr.AllColorsAsBlack = False
	'oPMgr.NumberOfCopies = 1
	'oPMgr.Printer = "MyPrinter"
	'oPMgr.RemoveLineWeights = False
	oPMgr.PrintRange = PrintRangeEnum.kPrintAllSheets
	oPMgr.ScaleMode = PrintScaleModeEnum.kPrintBestFitScale
	oPMgr.SubmitPrint
Next

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
Message 3 of 6

WCrihfield
Mentor
Mentor
Accepted solution

Oops...forgot to add the check in there for the custom iProperty, which was the whole point of this post.

Here try this version instead.

'check that the active document is an assembly file
If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then
	MessageBox.Show("Please run this rule from the assembly file.", "iLogic")
	Exit Sub
End If
'define the active document as an assembly file
Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
oAsmName = System.IO.Path.GetFileNameWithoutExtension(oAsmDoc.FullFileName)
'- - - - - - - - - - - - -Component Drawings - - - - - - - - - - - -'look at the files referenced by the assembly
Dim oRefDocs As DocumentsEnumerator = oAsmDoc.AllReferencedDocuments
Dim oRefDoc As Document
'work the the drawing files for the referenced models'this expects that the model has a drawing of the same path and name 
For Each oRefDoc In oRefDocs
	idwPathName = System.IO.Path.ChangeExtension(oRefDoc.FullFileName, ".idw")
	'check to see that the model has a drawing of the same path and name 
	If Not System.IO.File.Exists(idwPathName) Then Continue For
	Dim oDrawDoc As DrawingDocument = ThisApplication.Documents.Open(idwPathName, True)
	Dim oDCProps As PropertySet = oDrawDoc.PropertySets.Item("Inventor User Defined Propeties")
	If oDCProps.Count = 0 Then Continue For
	Dim oCPropFound As Boolean = False
	For Each oCProp As Inventor.Property In oDCProps
		If oCProp.Name = "ACS OP#" AndAlso oCProp.Value = 4 Then
			oCPropFound = True
		End If
	Next
	If oCPropFound = False Then Continue For
	Dim oPMgr As DrawingPrintManager = oDrawDoc.PrintManager
	'oPMgr.AllColorsAsBlack = False
	'oPMgr.NumberOfCopies = 1
	'oPMgr.Printer = "MyPrinter"
	'oPMgr.RemoveLineWeights = False
	oPMgr.PrintRange = PrintRangeEnum.kPrintAllSheets
	oPMgr.ScaleMode = PrintScaleModeEnum.kPrintBestFitScale
	oPMgr.SubmitPrint
Next

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 6

joshdollahan
Explorer
Explorer

I see where you are going, its the right start

It opens the first drawing and then errors. 

Invalid class string (Exception from HRESULT: 0x800401F3 (CO_E_CLASSSTRING))

 

System.Runtime.InteropServices.COMException (0x800401F3): Invalid class string (Exception from HRESULT: 0x800401F3 (CO_E_CLASSSTRING))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.PropertySets.get_Item(Object Index)
at LmiRuleScript.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

0 Likes
Message 5 of 6

WCrihfield
Mentor
Mentor

I see it.  I was typing too fast and left out the second "r" in "Properties" in the name of the custom PropertySet.

 

Dim oDCProps As PropertySet = oDrawDoc.PropertySets.Item("Inventor User Defined Properties")

 

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 6

joshdollahan
Explorer
Explorer

Yes that fixed it. Changed a few things for my purposes and will add to it later. I appreciate your help. This one closes each of the drawings that don't fit the criteria 

 

'check that the active document is an assembly file
If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then
    MessageBox.Show("Please run this rule from the assembly file.", "iLogic")
    Exit Sub
End If
'define the active document as an assembly file
Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
oAsmName = System.IO.Path.GetFileNameWithoutExtension(oAsmDoc.FullFileName)
'- - - - - - - - - - - - -Component Drawings - - - - - - - - - - - -'look at the files referenced by the assembly
Dim oRefDocs As DocumentsEnumerator
oRefDocs = oAsmDoc.AllReferencedDocuments
Dim oRefDoc As Document
For Each oRefDoc In oRefDocs
idwPathName = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentName) - 3) & "idw"
    
    'check to see that the model has a drawing of the same path and name 
    If Not System.IO.File.Exists(idwPathName) Then Continue For
    Dim oDrawDoc As DrawingDocument
                oDrawDoc = ThisApplication.Documents.Open(idwPathName, True)
                oFileName = Left(oRefDoc.DisplayName, Len(oRefDoc.DisplayName) -3)
    Dim oDCProps As PropertySet = oDrawDoc.PropertySets.Item("Inventor User Defined Properties")
    If oDCProps.Count = 0 Then Continue For
    Dim oCPropFound As Boolean = False
    For Each oCProp As Inventor.Property In oDCProps
        If oCProp.Name = "'your property here" AndAlso oCProp.Value = 'your value here Then
            oCPropFound = True
        End If
    Next
    If oCPropFound = True Then Continue For
    oDrawDoc.Close
Next

 

0 Likes