Using property values to define save directory

Using property values to define save directory

Anonymous
Not applicable
735 Views
2 Replies
Message 1 of 3

Using property values to define save directory

Anonymous
Not applicable

Hello,

 

i'm trying to automatically export a drawing to DWG and PDF to a certain directory.

This directory is defined by the client name (Klantnaam).

 

It works, but if i fill in the client name once, and then update the drawing, the pdf file wont be updated if i save the file again.

Also, the code that converts the drawing to DWG always gives an undefined error.. 

 

I hope someone can point me in the right direction

 

 

SyntaxEditor Code Snippet

Dim propertyName As String = "Klantnaam"
Dim propertyValue As String



customPropertySet = ThisDoc.Document.PropertySets.Item("Inventor User Defined Properties")
Try
prop = customPropertySet.Item(propertyName)
Catch
' Assume error means not found
customPropertySet.Add("", propertyName)
iProperties.Value("Custom", propertyName) = "null" 
End Try

If iProperties.Value("Custom", propertyName) = "null" Then
        propertyValue = InputBox("Voer klantnaam in : ", "Klantnaam", "")
        iProperties.Value("Custom", propertyName) = propertyValue
    End If
    
strFolder ="J:\Contacten\Klanten\" & propertyValue & "\Tekeningen\" & ThisDoc.FileName (False)
ThisDoc.Document.SaveAs(strFolder & (".pdf") , True)
' Get the DWG translator Add-In.
Dim DWGAddIn As TranslatorAddIn
DWGAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC2-122E-11D5-8E91-0010B541CD80}")
'Set a reference to the active document (the document to be published).
Dim oDocument As Document
oDocument = ThisApplication.ActiveDocument
Dim oContext As TranslationContext
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = kFileBrowseIOMechanism
' Create a NameValueMap object
Dim oOptions As NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
' Create a DataMedium object
Dim oDataMedium As DataMedium
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
' Check whether the translator has 'SaveCopyAs' options
If DWGAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
Dim strIniFile As String
strIniFile = "C:\temp\acad.ini"
' Create the name-value that specifies the ini file to use.
oOptions.Value("Export_Acad_IniFile") = strIniFile
End If
'Set the destination file name
Dim fileName As String
fileName = ThisDoc.FileName(False) & " -Rev " & iProperties.Value("Project", "Revision Number") & " Section cut "

oDataMedium.FileName = strFolder & ".dwg"
'Publish document.
Call DWGAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
0 Likes
Accepted solutions (1)
736 Views
2 Replies
Replies (2)
Message 2 of 3

Vladimir.Ananyev
Alumni
Alumni
Accepted solution

I've slightly changed your code and it works for me.
Could you test it on your side?

 

Option Explicit

'active drawing document
Dim oDoc As Inventor.Document = ThisDoc.Document

Dim propertyName As String = "Klantnaam"
Dim oProp As Inventor.Property
Dim propertyValue As String

'define the custom property "Klantnaam"
Dim oPropSet As PropertySet _
	= oDoc.PropertySets.Item("Inventor User Defined Properties")
Try
	oProp = oPropSet.Item(propertyName)
	propertyValue = oprop.Value
Catch
	' Assume error means not found
	oProp = oPropSet.Add("null", propertyName)
End Try
If oProp.Value = "null" Then
    propertyValue = InputBox("Voer klantnaam in : ", "Klantnaam", "")
    oProp.Value = propertyValue
End If

'folder path
Dim strFolder As String
'strFolder ="J:\Contacten\Klanten\" & propertyValue & "\Tekeningen\" & ThisDoc.FileName (False)
strFolder = "c:\temp\Klanten\" & propertyValue & "\Tekeningen\" 
'MsgBox(strfolder)

If Not System.IO.Directory.Exists(strfolder) Then
  	'create folder
     System.IO.Directory.CreateDirectory(strfolder)
'	 MsgBox("folder was created")
Else
	
End If

Dim fileName As String = strFolder & ThisDoc.FileName (False) & ".pdf"
'MsgBox(fileName)

'save pdf
oDoc.SaveAs(fileName, True)

Beep


' Get the DWG translator Add-In.
Dim DWGAddIn As TranslatorAddIn _
	= ThisApplication.ApplicationAddIns.ItemById("{C24E3AC2-122E-11D5-8E91-0010B541CD80}")
'create a context object
Dim oContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
' Create a NameValueMap object
Dim oOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
' Create a DataMedium object
Dim oDataMedium As DataMedium = ThisApplication.TransientObjects.CreateDataMedium

' Check whether the translator has 'SaveCopyAs' options
If DWGAddIn.HasSaveCopyAsOptions(oDoc, oContext, oOptions) Then
	Dim strIniFile As String = "C:\temp\acad.ini"	
	' Create the name-value that specifies the ini file to use.
	oOptions.Value("Export_Acad_IniFile") = strIniFile
End If

'Set the destination file name
fileName  = ThisDoc.FileName(False) & " -Rev " &  _
	iProperties.Value("Project", "Revision Number") & " Section cut "

oDataMedium.FileName = strFolder & filename & ".dwg"
'MsgBox(fileName)

'Publish dwg document.
Call DWGAddIn.SaveCopyAs(oDoc, oContext, oOptions, oDataMedium)

Beep

 cheers,


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 3

Anonymous
Not applicable

Works like a charm ! 

Thank you very much 

0 Likes