Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
cedric.pollet
364 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)