Manually referenced model to drawing (.idw) pdf output is different from programmatically referenced model drawing pdf

Manually referenced model to drawing (.idw) pdf output is different from programmatically referenced model drawing pdf

2020mme013
Enthusiast Enthusiast
184 Views
0 Replies
Message 1 of 1

Manually referenced model to drawing (.idw) pdf output is different from programmatically referenced model drawing pdf

2020mme013
Enthusiast
Enthusiast

I have created the members of ipart and given reference of the each member to drawings. The drawings have copied from a original drawing and saved in the same folder with their reference member.

after that I have used pdf addIn to export all idw files from that folder and save it in PDF folder. but output is not getting proper, except original drawing remaining all member drawings are getting higher in their weight. 

so I tried to give a reference of the member to the drawing manually and then the pdf output is getting perfect. what is missing I am not getting Can you please help me to this.

Here is the code for creating .ipt and drawings

-

-

-

Dim oDoc As PartDocument
oDoc = g_inventorApplication.ActiveDocument
Dim oFPath As String = oDoc.FullFileName
Dim iPrtF As iPartFactory
iPrtF = oDoc.ComponentDefinition.iPartFactory

'Current file path
Dim oPath As String = System.IO.Path.GetDirectoryName(oDoc.FullDocumentName)
'Get current filename without extension
Dim CurrentFilename As String = System.IO.Path.GetFileNameWithoutExtension(oDoc.FullDocumentName)
Dim CurrntPath As String = oPath & CurrentFilename & "\"
Dim oFirstMem As String = iPrtF.TableRows.Item(1).MemberName
Dim oDSuffix As String = ".idw"

'Check that the drawing for this part can be found
If Not System.IO.File.Exists(oPath & "\" & CurrentFilename & oDSuffix) Then
Dim oDCheck As Boolean = False
MessageBox.Show("Couldn't find the original Drawing document!", "Drawing")
Exit Sub
End If

Dim Path As String = oPath
Dim oCompDef As ComponentDefinition = oDoc.ComponentDefinition

Dim iPF As iPartFactory = oCompDef.iPartFactory

Dim oRow As iPartTableRow
Dim iPM As iPartMember

For Each oRow In iPF.TableRows
Dim oNewPart As PartDocument
Dim oCompDef2 As ComponentDefinition
Dim iPF2 As iPartFactory

iPF.DefaultRow = oRow
Dim oiPName As String
oiPName = oRow.PartName

Dim oiMNAme As String
oiMNAme = oRow.MemberName

'MsgBox(oiPName)
'Get current path

'MessageBox.Show(Path, "PAth")

' Perform Save As of Part
On Error Resume Next
Call oDoc.SaveAs(Path & "\" & oiPName, True)
'MessageBox.Show(Path & "\" & oiPName, "save")

oNewPart = Nothing
oNewPart = g_inventorApplication.Documents.Open(Path & "\" & oiPName, False)
oCompDef2 = Nothing
oCompDef2 = oNewPart.ComponentDefinition
iPF2 = Nothing
iPF2 = oCompDef2.iPartFactory
iPF2.Delete()
oNewPart.Save()
oNewPart.Close(True)

Dim DrawingDoc As DrawingDocument = g_inventorApplication.Documents.Open(oPath & "\" & CurrentFilename & oDSuffix, False)
' Replace reference to part model
Dim oFD As FileDescriptor
oFD = DrawingDoc.ReferencedDocumentDescriptors(1).ReferencedFileDescriptor
Call oFD.ReplaceReference(Path & "\" & oiPName)
DrawingDoc.Update()

' Perform 'Save As' on the drawing - change this to reflect your drawing type .dwg or .idw
DrawingDoc.SaveAs(Path & "\" & oiMNAme & oDSuffix, True)

DrawingDoc.Close(True)
Next
' Make the assembly model active again...
oDoc.Activate()

MessageBox.Show("Great, Members and Copy drawings are ready in same folder...")

 

Here is the Code for saving PDF

-

-

-

Dim oDoc As PartDocument
oDoc = g_inventorApplication.ActiveDocument
Dim oPath As String = System.IO.Path.GetDirectoryName(oDoc.FullDocumentName)

'-----get PDF target folder path-----
Dim oPDFFolder As String = Left(oPath, InStrRev(oPath, "\"))& "PDF"

'-----Check for the pdf folder and create it if it does not exist-----
If Not System.IO.Directory.Exists(oPDFFolder) Then
System.IO.Directory.CreateDirectory(oPDFFolder)
End If


'-----Search for idw's in folder-----
Dim MyFiles As String()

MyFiles = System.IO.Directory.GetFiles(oPath, "*.idw")

'-----Starts the Loop-----
For Each MyFile As String In MyFiles


g_inventorApplication.SilentOperation = True
Dim partDoc As Document = g_inventorApplication.Documents.Open(MyFile, False)
Dim CurrentFilename As String = System.IO.Path.GetFileNameWithoutExtension(partDoc.FullDocumentName)
On Error Resume Next

'Dim kDrawingDocumentObject As DocumentTypeEnum

'If partDoc.DocumentType = DrawingDocument Then

Dim oPropSet As PropertySet
Dim oProp As Inventor.Property
'Dim invPartNoProperty As Inventor.Property = partDoc.
'PropertySets.Item("Design Tracking Properties").Item("Part Number")
'Dim PartNumber As String = invPartNoProperty.Value

Dim oPDFAddIn As TranslatorAddIn
Dim oContext As TranslationContext
Dim oOptions As NameValueMap
Dim oDataMedium As DataMedium

'Dim iProperties As Object = Nothing
'Dim oRevNum = iProperties.Value("Project", "Revision Number")
oPDFAddIn = g_inventorApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
Dim oDocument As Document = g_inventorApplication.ActiveDocument
oContext = g_inventorApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = g_inventorApplication.TransientObjects.CreateNameValueMap
oDataMedium = g_inventorApplication.TransientObjects.CreateDataMedium

'-----Filename definition-----
Dim oFileName As String = oPDFFolder & "\" & CurrentFilename & ".pdf"

'-----Set the PDF target file name-----
oDataMedium.FileName = oFileName
'If oPDFAddIn.HasSaveCopyAsOptions(partDoc, oContext, oOptions) Then

' 'oRevNum = iProperties.Value("Project", "Revision Number")
' oOptions.Value("All_Color_AS_Black") = 0
' 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") = 4

'End If

 

'-----Publish document-----
oPDFAddIn.SaveCopyAs(partDoc, oContext, oOptions, oDataMedium)

'End If

partDoc.Close(False)
partDoc = Nothing
g_inventorApplication.SilentOperation = False

Next


'-----Opens PDF Folder-----
Shell("explorer.exe " & oPDFFolder, vbNormalFocus)Saved_through_Code pdf.pngManually refernced drawing pdf.png

0 Likes
185 Views
0 Replies
Replies (0)