Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Export DXF to specific location

1 REPLY 1
Reply
Message 1 of 2
cedric.pollet
286 Views, 1 Reply

Export DXF to specific location

Hello, I have written some code to export a IDW sheet to a DXF to a specific location on our company network. Only problem is that not all users have rights to modify or delete the file (only the admin and the user who did the export have full rights)

 

You can see my iLogic rule here:

 

Imports System
Imports System.IO
Imports System.Security.AccessControl

'********************************************Zet DXF instellingen******************************************

Dim DXFAddin As TranslatorAddIn
DXFAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-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 = IOMechanismEnum.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 DXFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then  
Dim strIniFile As String  
strIniFile = "C:\temp\dxfout.ini"  
' Create the name-value that specifies the ini file to use.  
oOptions.Value("Export_Acad_IniFile") = strIniFile  
End If  

'********************************************Creëer path******************************************
    
	'Dim sMaterial As String = ThisDoc.Document.ComponentDefinition.Material.Name
	'Dim sThickness As String = Parameter("Thickness")
	Dim sStockNr As String = iProperties.Value("Project", "Stock Number")
	Dim sStockNrLinks As String
	
	'trace.Writeline("Thickness: " & sThickness)
	
	If sStockNr = "" Then
		'vbLf = carriage return
		sStockNr= InputBox("Stocknummer niet ingevuld !" & vbLf & "Geef stocknummer in:", "Onvolledig" , "")
	End If
	
	'Controleer of stocknummer 5 tekens bevat
	If Len(sStockNr) <> 5 Then
		i = MessageBox.Show("Ongeldig stocknummer ingegeven !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1)
		Return
	End If
	
	sStockNrLinks = Left(sStockNr,2)+"000"	'Voorlopig niet boven 100.000
	
	trace.Writeline(sStockNr.ToString() & Chr(13) & sStockNrLinks.ToString() )
	
	Dim sPATH As String
	sPATH = "L:\ASCI\PRODUCTEN\" & sStockNrLinks & "\" & sStockNr
	
	Dim sFilePath As String
	sFilePath = sPATH & "\" & sStockNr & "_" & ThisDoc.FileName(False) & ".dxf"
	
	'Dim UserAccount As String = "BASCULESROBBE\Users"
	Dim UserAccount As String = "Everyone"
	
	
	Dim FileInfo As IO.FileInfo = New IO.FileInfo(sFilePath)
	Dim FileAcl As New FileSecurity
	trace.Writeline("FileACL aangemaakt")
	
	'FolderAcl.AddAccessRule(New FileSystemAccessRule(UserAccount, FileSystemRights.Modify, InheritanceFlags.ContainerInherit Or InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow))
	'FolderAcl.AddAccessRule(New FileSystemAccessRule(UserAccount, FileSystemRights.Modify, InheritanceFlags.None, PropagationFlags.None, AccessControlType.Allow))
	FileAcl.AddAccessRule(New FileSystemAccessRule(UserAccount, FileSystemRights.Modify, AccessControlType.Deny))
	
	trace.Writeline("Add accessrule ok")
	
	FileInfo.SetAccessControl(FileAcl)
	trace.Writeline("SetAccessControl ok")
	
	'Kijk of path bestaat en creer indien het niet bestaat
	If Not System.IO.Directory.Exists(sPATH) Then
		System.IO.Directory.CreateDirectory(sPATH)
	End If


'Set the destination file name  
'oDataMedium.FileName = ThisDoc.PathAndFileName(False) & sheetname & ".dxf" 'same folder, or uncomment:  

oDataMedium.FileName= sFilePath
'oDataMedium.FileName = "L:\ASCI\PRODUCTEN\14000\14001\14001_0150001.dxf\" & ThisDoc.FileName(False) & ".dxf" 'fixed folder  
'Publish document.  

DXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)  
'Launch the dxf file in whatever application Windows is set to open this document type with  
i = MessageBox.Show("Preview the DXF file?", "Title",MessageBoxButtons.YesNo,MessageBoxIcon.Question)  
If i = vbYes Then ThisDoc.Launch(oDataMedium.FileName)  

 

The code executes till the FileAcl.AddAccessRule

 

I get the following error:

 

Error in rule: Rule4, in document: 0150092.idw

Some or all identity references could not be translated.

 

System.Security.Principal.IdentityNotMappedException: Some or all identity references could not be translated.
   at System.Security.Principal.NTAccount.Translate(IdentityReferenceCollection sourceAccounts, Type targetType, Boolean forceSuccess)
   at System.Security.Principal.NTAccount.Translate(Type targetType)
   at System.Security.AccessControl.CommonObjectSecurity.ModifyAccess(AccessControlModification modification, AccessRule rule, Boolean& modified)
   at System.Security.AccessControl.CommonObjectSecurity.AddAccessRule(AccessRule rule)
   at LmiRuleScript.Main()
   at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
   at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

Anyone got an idea what the problem might be ?

 

Thanks in advance,

Greetings

Cedric

Tags (3)
1 REPLY 1
Message 2 of 2
GosponZ
in reply to: cedric.pollet

Thry this one

oPath = ThisDoc.Path

        oFileName = ThisDoc.FileName(False) 'without extension

        oDXFAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}")

        oDocument = ThisApplication.ActiveDocument

        oContext = ThisApplication.TransientObjects.CreateTranslationContext

        oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism

        oOptions = ThisApplication.TransientObjects.CreateNameValueMap

        oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

        'Define the drawing 

        Dim oDrawing As DrawingDocument

        oDrawing = ThisDoc.Document

        Dim oSheet As Sheet

        Dim lPos As Long

        Dim rPos As Long

        Dim sLen As Long

        Dim sSheetName As String

        Dim sSheetNumber As Integer

        'step through each drawing sheet

Dim Response As MsgboxResult

        For Each oSheet In oDrawing.Sheets

            Response = MsgBox("Yes = Save or No = Continue to next Sheet?", MsgBoxStyle.YesNo, "Question")
           If Response = MsgBoxResult.Yes Then
                'find the seperator in the sheet name:number
                lPos = InStr(oSheet.Name, ":")
                'find the number of characters in the sheet name
                sLen = Len(oSheet.Name)
                'find the sheet name
                sSheetName = Left(oSheet.Name, lPos - 1)
              'find the sheet numbe
            sSheetNumber = Right(oSheet.Name, sLen - lPos)
End If
ActiveSheet = ThisDrawing.Sheet(oSheet.Name)
            If Response = MsgBoxResult.Yes Then
                'find the seperator in the sheet name:number
                lPos = InStr(oSheet.Name, ":")
                'find the number of characters in the sheet name
                sLen = Len(oSheet.Name)
                'find the sheet name
                sSheetName = Left(oSheet.Name, lPos - 1)
                'find the sheet numbe
            sSheetNumber = Right(oSheet.Name, sLen - lPos)



      'get DXF target folder path

                oFolder = "c:\INVENTOR DXF FILES"



                'Set the DXF target file name

                oDataMedium.FileName = oFolder & "\" & sSheetName & sSheetNumber & ".dxf"


                MessageBox.Show("DXF SAVED TO: " & oDataMedium.FileName, "DXF Saved", MessageBoxButtons.OK)

                'Publish document

                oDXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)

            End If
        Next





Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report