Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Want to export DWG + PDF after converting inches to mm

machiel.veldkamp
Collaborator

Want to export DWG + PDF after converting inches to mm

machiel.veldkamp
Collaborator
Collaborator

We need to open drawings change the dimensions units from IMPERIAL to METRIC and then export it to a specific folder. 

 

 

We can't make new styles so I want to change the thing in the picture I provided. 

 

 

image.png

I already made the code to export all dwg's from a drawing. I now just need to change the inches to mm before I export. 

 

But I don't know how! Can anyone point me in the right direction here? 

 

SyntaxEditor Code Snippet

'define the active document as an assembly file
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
oAsmName = Left(oAsmDoc.DisplayName, Len(oAsmDoc.DisplayName))
oRevNum = iProperties.Value("Project", "Revision Number")

'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

'get user input
RUsure = MessageBox.Show ( _
"This will create a PDF file for all of the assembly components that have drawing (dwg) 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 assembly components?" _
& vbLf & " " _
& vbLf & "This could take a while.", "iLogic  - Batch Output PDFs ",MessageBoxButtons.YesNo)

If RUsure = vbNo Then
Return
Else
End If

'- - - - - - - - - - - - -PDF setup - - - - - - - - - - - -
oPath = "G:\Wet & Dry Technology BV\Resato Snijmachine\EXPORT MAP" 
PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
Dim oDWGAddIn As TranslatorAddIn
oDWGAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC2-122E-11D5-8E91-0010B541CD80}")
oDataMediumDWG = ThisApplication.TransientObjects.CreateDataMedium

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") = 1

'get PDF target folder path
oFolder = oPath & "\" & oAsmName & "-PDF"

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

'- - - - - - - - - - - - DWG SETUP - - - - - - - - - - - - - -  

strIniFile = "G:\Wet & Dry Technology BV\Algemeen\Folders Medewerkers\Veldkamp, Machiel\INVENTOR\iLogic\DWG_MODEL.ini"  'INI FILE IS MODELSPACE
' Create the name-value that specifies the ini file to use.
oOptions.Value("Export_Acad_IniFile") = strIniFile

'- - - - - - - - - - - - -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
	'CHANGE INCHES TO MM FIRST - AFTER THAT, EXPORT
	dwgPathName = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentName)-3) & "dwg"
	'check to see that the model has a drawing of the same path and name
	If(System.IO.File.Exists(dwgPathName)) Then
				Dim oDrawDoc As DrawingDocument
				oDrawDoc = ThisApplication.Documents.Open(dwgPathName, True)
				oFileName = Left(oRefDoc.DisplayName, Len(oRefDoc.DisplayName))'- 3)
				'MessageBox.Show(oFileName, "Title")


	            On Error Resume Next ' if PDF exists and is open or read only, resume next
	                 'Set the PDF target file name
	                oDataMedium.FileName = oFolder & "\" & oFileName & ".pdf"
					oDataMediumDWG.FileName = oFolder & "\" & oFileName  & ".dwg"
	                'Write out the PDF
	                PDFAddIn.SaveCopyAs(oDrawDoc, oContext, oOptions, oDataMedium)
					oDWGAddIn.SaveCopyAs(oDrawDoc, oContext, oOptions, oDataMediumDWG)
	            	'close the file
	                oDrawDoc.Close
	Else
	'If the model has no drawing of the same path and name - do nothing
	End If
Next

'- - - - - - - - - - - - -Top Level Drawing - - - - - - - - - - - -
oAsmDrawing = ThisDoc.ChangeExtension(".dwg")
oAsmDrawingDoc = ThisApplication.Documents.Open(oAsmDrawing, True)
oAsmDrawingName = Left(oAsmDrawingDoc.DisplayName, Len(oAsmDrawingDoc.DisplayName) -3)
'write out the PDF for the Top Level Assembly Drawing file
On Error Resume Next ' if PDF exists and is open or read only, resume next
 'Set the PDF target file name
oDataMedium.FileName = oFolder & "\" & oAsmDrawingName & ".pdf"
'Write out the PDF
Call PDFAddIn.SaveCopyAs(oAsmDrawingDoc, oContext, oOptions, oDataMedium)
oDataMediumDWG.FileName = oFolder & "\" & oAsmDrawingName  & ".dwg"
oDWGAddIn.SaveCopyAs(oAsmDrawingDoc, oContext, oOptions, oDataMediumDWG)
'Close the top level drawing
oAsmDrawingDoc.Close
'- - - - - - - - - - - - -

MessageBox.Show("New Files Created in: " & vbLf & oFolder, "iLogic")
'open the folder where the new ffiles are saved
Shell("explorer.exe " & oFolder, vbNormalFocus)

 

 

 

 

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

___________________________
0 Likes
Reply
Accepted solutions (2)
1,006 Views
9 Replies
Replies (9)

HermJan.Otterman
Advisor
Advisor

 

try, look at: DimensionStyle.LinearUnits() As UnitsTypeEnum

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


0 Likes

machiel.veldkamp
Collaborator
Collaborator

Hi @HermJan.Otterman

Thanks! 

 

I tried this and failed. I'm close though!

 

 

 

For Each oRefDoc In oRefDocs
	'CHANGE INCHES TO MM FIRST - AFTER THAT, EXPORT
	

	
	
	dwgPathName = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentName)-3) & "dwg"
	'check to see that the model has a drawing of the same path and name
	If(System.IO.File.Exists(dwgPathName)) Then
				Dim oDrawDoc As DrawingDocument
				oDrawDoc = ThisApplication.Documents.Open(dwgPathName, True)
					
					
					
					
					
					Dim oStylesMgr As DrawingStylesManager = oDrawDoc.StylesManager
					MessageBox.Show(dwgPathName, "titel" )
					MessageBox.Show(oStylesMgr.ActiveStandardStyle.LinearUnits, "Title")
		                        MessageBox.Show(oStylesMgr.ActiveStandardStyle.InternalName, "titel" )
					
---> This is the wrong setting		oStylesMgr.ActiveStandardStyle.LinearUnits = UnitsTypeEnum.kMillimeterLengthUnits
					
					
					'MessageBox.Show(Kaas, "Title")
---> This is not allowed		oStylesMgr.DimensionStyles.Type = UnitsTypeEnum.kMillimeterLengthUnits

@Curtis_Waguespack Maybe you can figure out how with your magic?

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

___________________________
0 Likes

machiel.veldkamp
Collaborator
Collaborator

@bradeneuropeArthur Perhaps you have some pointers too? 

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

___________________________
0 Likes

bradeneuropeArthur
Mentor
Mentor

Yes I have:

 

Public Sub ChangeDimensionStyleUnit()

'check if the active document is a drawing document
 If ThisApplication.ActiveDocumentType = kDrawingDocumentObject Then
Dim oIDW As DrawingDocument
Set oIDW = ThisApplication.ActiveDocument
 
Dim oIDWStyles As Inventor.DrawingStylesManager
Set oIDWStyles = oIDW.StylesManager

'MsgBox oIDWStyles.RevisionTableStyles.Count
'Debug.Print oIDWStyles.DimensionStyle
MsgBox oIDWStyles.DimensionStyles.Item("YOUR DIM STYLE").LinearUnits

oIDWStyles.DimensionStyles.Item("BE_DIMENSION").LinearUnits = kInchLengthUnits



 Else

 
 End If
 End Sub

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

0 Likes

bradeneuropeArthur
Mentor
Mentor
Accepted solution

Afterwards:

 

Public Sub UpdateRevisionTableStyle()

'check if the active document is a drawing document
 If ThisApplication.ActiveDocumentType = kDrawingDocumentObject Then
Dim oIDW As DrawingDocument
Set oIDW = ThisApplication.ActiveDocument
 
Dim oIDWStyles As Inventor.DrawingStylesManager
Set oIDWStyles = oIDW.StylesManager

'Debug.Print oIDWStyles.DimensionStyle
MsgBox oIDWStyles.DimensionStyles.Item("BE_DIMENSION").LinearUnits

oIDWStyles.DimensionStyles.Item("YOUR DIM STYLE").LinearUnits = kInchLengthUnits
'YOUR CODE HERE
oIDWStyles.DimensionStyles.Item("YOUR DIM STYLE").LinearUnits= kMillimeterLengthUnits 

 Else

 End If
 End Sub

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

0 Likes

machiel.veldkamp
Collaborator
Collaborator

Awesome! 

I got it!

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

___________________________
0 Likes

bradeneuropeArthur
Mentor
Mentor
Hi,

Question:
How come that you mentioned me, i was not in this topic yet.
This is no problem, but i am curious only.

Good to hear that i could have helped you.

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

0 Likes

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi machiel.veldkamp,

 

I'm a bit late to this discussion, but this is what I came up with.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

Dim oDrawDoc As DrawingDocument 
Dim oSheet As Sheet

'get the current drawing
oDrawDoc = ThisDoc.Document
'get the active sheet
oSheet = oDrawDoc.ActiveSheet

' Set a reference to the first general dimension in the collection.
Dim oGeneralDim As GeneralDimension
oGeneralDim = oSheet.DrawingDimensions.GeneralDimensions.Item(1)

' Set a reference to the dimension style of that dimension.
Dim oDimStyle As DimensionStyle
oDimStyle = oGeneralDim.Style

' Change units property of the dimension style to mm
' This will modify all dimensions that use this style.
oDimStyle.LinearUnits = UnitsTypeEnum.kMillimeterLengthUnits 
	
MessageBox.Show("EXPORT DXF CODE HERE", "iLogic")
	
' Change units property of the dimension style back to inches
' This will modify all dimensions that use this style.
oDimStyle.LinearUnits = UnitsTypeEnum.kInchLengthUnits 

 

0 Likes

machiel.veldkamp
Collaborator
Collaborator

@bradeneuropeArthur Well. I saw you replying to someone else in a similar topic. I thought you might be able to contribute :slightly_smiling_face:

 

 

Awesome sauce. Thanks again @Curtis_Waguespack@bradeneuropeArthur and @HermJan.Otterman for the help. 

Still learning, getting better :grinning_face_with_smiling_eyes:

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

___________________________
0 Likes