How to Access Iproperty of DWG files opened from an Assembly Referenced Documents?

How to Access Iproperty of DWG files opened from an Assembly Referenced Documents?

wCorreiaHBYAR
Explorer Explorer
254 Views
1 Reply
Message 1 of 2

How to Access Iproperty of DWG files opened from an Assembly Referenced Documents?

wCorreiaHBYAR
Explorer
Explorer

HI, I am able to open and SAVE as PDF for the DWG that are linked to an Assembly. But I am not able to get the REV # that is in the Custom iproperty of each DWG.

I used the below line in many ways but no success: 

iProperties.Value("Custom", "REV #")

 But since  I am running the RULE from an assembly. The RULE does not pick up the REV# that is in the DWG's "Custom" iproperty. Looks like I am missing a piece of code that will do it. I plan to use that REV# and put it in the PDF file name that is generated. Can anyone help me? Here is my entire code:

Sub Main()
    Dim oDoc As Document
    oDoc = ThisDoc.Document
    oDocName = System.IO.Path.GetDirectoryName(oDoc.FullFileName) & "\" & System.IO.Path.GetFileNameWithoutExtension(oDoc.FullFileName)
'	oFile = GetFileNameWithoutExtension(oDoc.FullFileName)
    'MessageBox.Show(oFile, "Title")

    If Not (oDoc.DocumentType = kAssemblyDocumentObject Or oDoc.DocumentType = kDrawingDocumentObject) Then
        MessageBox.Show("Please run this rule from the assembly or drawing files.", "iLogic")
        Exit Sub
    End If
    
    'get user input
    If MessageBox.Show ( _
        "This will create a PDF file for all of the files referenced by this document that have drawings files." _
        & vbLf & "This rule expects that the drawing file shares the same name and location as the component." _
        & vbLf & " " _
        & vbLf & "Are you sure you want to create PDF Drawings for all of the referenced documents?" _
        & vbLf & "This could take a while.", "iLogic  - Batch Output PDFs ",MessageBoxButtons.YesNo) = vbNo Then
        Exit Sub
    End If
        
    Dim PDFAddIn As TranslatorAddIn
    Dim oContext As TranslationContext
    Dim oOptions As NameValueMap
    Dim oDataMedium As DataMedium
    
    Call ConfigurePDFAddinSettings(PDFAddIn, oContext, oOptions, oDataMedium)
	'Call GetPropertySample
	'-----------------------------------------
	' Folder Selection
		Dim oFolder As String = ThisDoc.Path
		Dim Dialog = New FolderBrowserDialog()
		Dialog.SelectedPath = oFolder
		Dialog.ShowNewFolderButton = True
		Dialog.Description = "Select Or Create A Folder Where You want PDFs TO be Created"
		If DialogResult.OK = Dialog.ShowDialog() Then
			oFolder = Dialog.SelectedPath 
		'MessageBox.Show(oFolder, "Title")
		End If
	'	------------------
    
'    If Not System.IO.Directory.Exists(oFolder) Then
'        System.IO.Directory.CreateDirectory(oFolder)
'    End If

    
'    '- - - - - - - - - - - - -Component Drawings - - - - - - - - - - - -
    Dim oRefDoc As Document
    Dim oDrawDoc As DrawingDocument
	Dim oPenDoc As  Inventor.DrawingDocument
    
    For Each oRefDoc In oDoc.AllReferencedDocuments
        oBaseName = System.IO.Path.GetFileNameWithoutExtension(oRefDoc.FullFileName)
        oPathAndName = System.IO.Path.GetDirectoryName(oRefDoc.FullFileName) & "\" & oBaseName
        If(System.IO.File.Exists(oPathAndName & ".dwg")) Then
            oDrawDoc = ThisApplication.Documents.Open(oPathAndName & ".dwg", True) 
			
'NEED HELP HERE IN GETTING THE REV# FROM THE CUSTOM IPROPERTY OF THE DWG THAT IS OPEN IN ABOVE LINE			
			
			
			oDataMedium.FileName = oFolder & "\" & oBaseName  & ".pdf"
           Call PDFAddIn.SaveCopyAs(oDrawDoc, oContext, oOptions, oDataMedium)
            oDrawDoc.Close(True)
        Else
            oNoDwgString = oNoDwgString & vbLf & dwgPathName
        End If
    Next
'    '- - - - - - - - - - - - -xx - - - - - - - - - - - - - - - - - - - -
    
'    '- - - - - - - - - - - - -Top Level Drawing - - - - - - - - - - - -
    oBaseName = System.IO.Path.GetFileNameWithoutExtension(oDoc.FullFileName)
    oPathAndName = System.IO.Path.GetDirectoryName(oDoc.FullFileName) & "\" & oBaseName
    oDataMedium.FileName = oFolder & "\" & oBaseName & ".pdf"
    
    If oDoc.DocumentType = kAssemblyDocumentObject Then
        oDrawDoc = ThisApplication.Documents.Open(oPathAndName & ".dwg", False)
        Call PDFAddIn.SaveCopyAs(oDrawDoc, oContext, oOptions, oDataMedium)
        oDrawDoc.Close
    ElseIf oDoc.DocumentType = kDrawingDocumentObject Then
        Call PDFAddIn.SaveCopyAs(oDoc, oContext, oOptions, oDataMedium)    
    End If
'    '- - - - - - - - - - - - -
    
    MessageBox.Show("New Files Created in: " & vbLf & oFolder, "iLogic")
    'MsgBox("Files found without drawings: " & vbLf & oNoDwgString)
    Shell("explorer.exe " & oFolder,vbNormalFocus)
End Sub
 
 


Sub ConfigurePDFAddinSettings(ByRef PDFAddIn As TranslatorAddIn, ByRef oContext As TranslationContext, ByRef oOptions As NameValueMap, ByRef oDataMedium As DataMedium)

    PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
    oContext = ThisApplication.TransientObjects.CreateTranslationContext
    oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
    oOptions = ThisApplication.TransientObjects.CreateNameValueMap
    oOptions.Value("All_Color_AS_Black") = 1
    oOptions.Value("Remove_Line_Weights") = 0
    oOptions.Value("Vector_Resolution") = 400
    oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
    oOptions.Value("Custom_Begin_Sheet") = 1
    oOptions.Value("Custom_End_Sheet") = 1
    oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

End Sub

wCorreiaHBYAR_1-1648046349613.png

 

 

 


@ nigel.hay @Curtis_W. @MechMachineMan 

 

0 Likes
Accepted solutions (1)
255 Views
1 Reply
Reply (1)
Message 2 of 2

WCrihfield
Mentor
Mentor
Accepted solution

Try a code like this to get the value of that custom iProperty for the drawing you are about to export as PDF:

 

oRevNum = oDrawDoc.PropertySets.Item("Inventor User Defined Properties").Item("REV #").Value

 

Beware though...if that custom iProperty does not exist in that document, this line will throw an error.  You can avoid that though by using a couple more lines of code to check if it exists, before trying to get its value.

I don't know if the data that you put as the Value of that iProperty is a String or Integer, but it would most likely be best to pre-define the Type of the variable 'oRevNum' (or whatever variable you want to use).  If it is a String value then:  Dim oRevNum As String...then you can check if it was empty or not by: If oRevNum = "", to avoid potential errors/issues.

 

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

If you want and have time, I would appreciate your Vote(s) for My IDEAS :bulb: or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)