Ilogic output from rule to user desktop

Ilogic output from rule to user desktop

bsnyderACLUW
Enthusiast Enthusiast
1,054 Views
11 Replies
Message 1 of 12

Ilogic output from rule to user desktop

bsnyderACLUW
Enthusiast
Enthusiast

Hi everyone,

 

I have a simple question that should have a simple answer (I hope). I am trying to run an External Rule that creates DXF's and outputs them to the desktop. The rule itself works great but i want to be able to use this across many accounts (as it only works on mine right now). Simply put, I have the output path as: C:\Users\bsnyder\Desktop\PDFs but I want to replace "bsnyder" with a generic term that will work on any machine. I have had no luck with  finding solutions to this issue. So far I have tried several versions of adding special characters to the term Username or Userpath with no luck. I have also tried things like :

Dim oFolder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\PDFs"

 Any help would be appreciated.

 

Thank you,

0 Likes
Accepted solutions (2)
1,055 Views
11 Replies
Replies (11)
Message 2 of 12

FINET_Laurent
Advisor
Advisor

Morning,

 

When running this rule what do you get ?

 

Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument
Dim sStr As String = oDoc.FullFileName
MsgBox(sStr)

 

If you get C:\Users\bsnyder\.. you could delete the terms you don't need and add "Desktop\PDFs".

 

Regards,

 

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

0 Likes
Message 3 of 12

bsnyderACLUW
Enthusiast
Enthusiast

@FINET_Laurent ,

 

Sorry but that code doesn't help. My model files are stored elsewhere on my computer. 

I have an Ilogic code that creates PDF's of my drawings and dumps them onto the PDF's folder on my desktop but that program sends the information from the drawing to Bullzip where Bullzip "Prints" the drawing and places the PDF in this folder. I want to use the same destination folder for the DXF program I am making. I cant use C:\Users\bsnyder as there are many others that will be using this program to make DXF's. I know there are other terms you can use for the username (bsnyder) that are generic but I cant find the one that Ilogic will accept. 

 

Thank you for your reply,

0 Likes
Message 4 of 12

blandb
Mentor
Mentor

Is there a reason you can't dump these to a shared network drive vs. your desktop?

Autodesk Certified Professional
Message 5 of 12

bsnyderACLUW
Enthusiast
Enthusiast

@blandb

 

I would prefer that myself, would make things much easier when passing information to our document coordinators. unfortunately I don't make those decisions nor does my opinion carry weight. 

 

I did find a work around today, it now allows the user to choose a file path. I would still prefer it to be automated but this will work if it cannot be done. 

 

Imports System.Windows.Forms
' Define folder browse dialog
Dim Dialog = New FolderBrowserDialog()

' Set options for folder browser dialog
Dialog.SelectedPath = oPath
Dialog.ShowNewFolderButton = True
Dialog.Description = "Choose Folder for Export..."

' Show dialog box
If DialogResult.OK = Dialog.ShowDialog() Then
	' User clicked 'ok' on dialog box - capture the export path
	oPath = Dialog.SelectedPath & "\"
	
Else
	' User clicked 'cancel' on dialog box - exit
	Return
End If

thank you

0 Likes
Message 6 of 12

J-Camper
Advisor
Advisor

You were close before, try this:

MessageBox.Show(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "Title")

You just needed to specify the DesktopDirectory, not just the Desktop.

0 Likes
Message 7 of 12

bsnyderACLUW
Enthusiast
Enthusiast

@J-Camper 

 

I get an error when running this in the rule:

 

bsnyderACLUW_0-1603833463882.png

 

thank you,

0 Likes
Message 8 of 12

FINET_Laurent
Advisor
Advisor
Accepted solution

You could make a string list of the user names and try to export the Dxf for each string in the list with try/catch..

This is barbaric but it whould work. I Don't see any way around. Can you provide a list ?

 

Something like this (I don't have much time today)

 

Dim User As List(Of String) = New List(Of String)

	User.Add("UserX")
	User.Add("UserY")
	User.Add("UserZ")

Dim sString As Object

For Each sString In User

	Try 
		Dim sPath As String = "C:\Users\" & sString & "\Desktop\PDFs"
		
			'Export  dxf command
	Catch 
		
		'do nothing if error occurs (wrong user name)
		
	End Try 
	
Next

Regards,

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

Message 9 of 12

J-Camper
Advisor
Advisor

That's weird, it works for me in iLogic on 2019 Inventor.  What year Inventor are you using?  Are you writing iLogic code or a VBA Macro?

 

I don't know if Importing the System Environment would help?

 

Imports System.Environment
MessageBox.Show(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "Title")

 

It makes no difference on my system, but the line worked for me to begin with.

 

It might work better if you specify System.Envirnoment in the Call?

MessageBox.Show(System.Environment.GetFolderPath(System.Environment.SpecialFolder.DesktopDirectory), "Title")

 This also works for me without error.

0 Likes
Message 10 of 12

bsnyderACLUW
Enthusiast
Enthusiast

@FINET_Laurent 

 

That is a decent solution. I will keep that in mind. Thank you

 

@J-Camper 

I guess I am miss interpreting how to use this line of code. I am running 2019 and i am using Ilogic to run this code. When I run the system.environment version I get a message box :

bsnyderACLUW_1-1603915591818.png

 

Then I get the error after selecting OK.

bsnyderACLUW_5-1603915654933.png

From what I can tell it is referencing the desktop but not the specific folder I need. If I am right, I don't know how to add this. 

 

 Bellow is the code I am using:

'Imports System.Windows.Forms
Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument

'If document is not assembly, alert user and exit rule
If oDoc.DocumentType <> kAssemblyDocumentObject Then
    MessageBox.Show("This rule must be run from an Assembly.", "iLogic")
    Exit Sub
End If

'get user input
RUsure = MessageBox.Show ( _
"This will create a DXF file for all sheet metal components." _
& vbLf & " " _
& vbLf & "Are you sure you want to create a DXF for all of the sheet metal components in this assembly?", "iLogic - Generate DXF's ",MessageBoxButtons.YesNo)
If RUsure = vbNo Then
    Return
 Else
End If

'- - - - - - - - - - - - -Establish DXF Save Path - - - - - - - - - - - -
' Define folder browse dialog
'Dim Dialog = New FolderBrowserDialog()

' Set options for folder browser dialog
'Dialog.SelectedPath = oPath
'Dialog.ShowNewFolderButton = True
'Dialog.Description = "Choose Folder for Export..."

' Show dialog box
'If DialogResult.OK = Dialog.ShowDialog() Then
	' User clicked 'ok' on dialog box - capture the export path
'	oPath = Dialog.SelectedPath & "\"
	
'Else
	' User clicked 'cancel' on dialog box - exit
'	Return
'End If
oPath = MessageBox.Show(System.Environment.GetFolderPath(System.Environment.SpecialFolder.DesktopDirectory), "DXFs")
'- - - - - - - - - - - - -Components - - - - - - - - - - - -
Dim oRefDocs As DocumentsEnumerator
Dim oRefDoc As Document
oRefDocs = oDoc.AllReferencedDocuments

'Iterate through referenced docs
For Each oRefDoc In oRefDocs
    Dim oCurFile As Document 'current file
    Try
        oCurFile = ThisApplication.Documents.Open(oRefDoc.FullFileName, False) 
            'False == open invisible, True == open visible. invisible is much faster.
     Catch
        GoTo NextIteration
    End Try
    
    If oCurFile.DocumentSubType.DocumentSubTypeID <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
        'document is not sheet metal. 
        oCurFile.Close(True) 'True == skip save
    Else
        oCurFileName = oCurFile.FullFileName
    
        'get the postion of the last backslash in the path
        FNamePos = InStrRev(oCurFileName, "\", -1)
        'get the file name with the file extension
        FName = Right(oCurFileName, Len(oCurFileName) - FNamePos)
        'get the file name (without extension)
        FName = Left(FName, Len(FName) - 4)
        'set dxf filename
        DxfName = oPath & FName & ".dxf"

        Dim oSMCD As SheetMetalComponentDefinition
		oSMCD = oCurFile.ComponentDefinition
        If oSMCD.HasFlatPattern = False Then 'If it doesn't have a flat pattern, create one (unfold the model)
            oSMCD.Unfold()
		Else
            oSMCD.FlatPattern.ExitEdit()
        End If

        'set dxf options
		Dim sOut As String
		sOut = "FLAT PATTERN DXF?AcadVersion=2004&RebaseGeometry=True&OuterProfileLayer=0&OuterProfileLayerColor=0;0;0&InteriorProfilesLayer=0&InteriorProfilesLayerColor=0;0;0&InvisibleLayers=IV_ARC_CENTERS;IV_TANGENT;IV_ROLL;IV_ROLL_TANGENT;IV_ALTREP_BACK;IV_ALTREP_FRONT;IV_FEATURE_PROFILES_DOWN;IV_FEATURE_PROFILES;IV_TOOL_CENTER_DOWN;DIGI_MARKER_TOOL_1;DIGI_MARKER_TOOL_2;IV_BEND;IV_BEND_DOWN"

        
        Call oSMCD.DataIO.WriteDataToFile(sOut, DxfName) 'save the dxf
        
		oSMCD.FlatPattern.ExitEdit
        oCurFile.Close
    End If	
	NextIteration:
Next

'- - - - - - - Display Results - - - - - - - - - - - - -
'MessageBox.Show("New Files Created in: " & vbLf & oPath & vbLf & vbLf & "Please verify that all DXFs are correct.", "iLogic")

'open the folder where the new files are saved
Shell("explorer.exe " & oPath,vbNormalFocus)

 

0 Likes
Message 11 of 12

J-Camper
Advisor
Advisor
Accepted solution

I only had it in the MessageBox to test without variables, I think your actual code should look like this [where you are setting oPath]:

'set target path
oPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.DesktopDirectory) & "\PDFs"
'create target folder if it does not exist
If Not System.IO.Directory.Exists(oPath) Then System.IO.Directory.CreateDirectory(oPath)

MessageBox.Show(oPath, "Path Preview")'remove this after testing

then when saving files to it you should set it up something like this:

Fname = oPath & "\" & "GeneratedNameString" & ".pdf"

 Let me know if you have any questions or if it isn't working as expected.

Message 12 of 12

bsnyderACLUW
Enthusiast
Enthusiast

@J-Camper 

 

Thank you so much!!! it works great.

I just added the first part you posted changing "\PDFs" to "\PDFs\" and worked like a charm!!!

 

Thanks a bunch,

0 Likes