iLogic Rule That Runs on Save As

iLogic Rule That Runs on Save As

jmsantangelo61
Participant Participant
582 Views
7 Replies
Message 1 of 8

iLogic Rule That Runs on Save As

jmsantangelo61
Participant
Participant

There is currently no Save As event trigger, only before save or after save.  Is it possible to create a Save as trigger, or incorporate it into the iLogic code for the rule?  Many of our parts are very similar to existing parts, so we open the existing part, save as new file name, then make the minor changes.  We are adding a "similar to" box to our title block so the shop has a reference part they can look up their existing CNC program for and make the minor changes to the program and run it instead of writing a new program every time.  I would like the "similar to" box to automatically populate on the drawing base on the part number of the original part, before the save as and new part creation.  I wrote a code that is able to add the part number of the existing file into an iproperty of the new part, then I can link the iproperty to the "similar to" box.  The only way the code works properly is with the before save event trigger though.  The issue is that any subsequent save of the new part will then update the iproperty to the current part number.  I am very new to iLogic program and don't have a fundamental understanding of it yet, so any help would be greatly appreciated.  Below is the current code I am using.

Dim activeDocName As String = ThisApplication.ActiveDocument.FullFileName
Dim thisDocName As String = ThisDoc.Document.FullFileName

If (activeDocName = thisDocName) Then
	iProperties.Value("Summary", "Subject") = ThisDoc.FileName(False) 'without extension
End If

 

0 Likes
Accepted solutions (1)
583 Views
7 Replies
Replies (7)
Message 2 of 8

A.Acheson
Mentor
Mentor

Hi @jmsantangelo61 

If I understand you correctly you want to transfer an iProperty from the open part to the newly created Save As part is that correct? In that case I would not put this into any internal or external rule based on an events trigger because simply as you have already found out there is  not a suitable way to monitor this kind of operation. What you can do is to setup a utility rule manually run by the user in an external rule. The challenge would be to remember to use it as you work. 

Se below

Dim referencePN As String = iProperties.Value("Project", "Part Number")
Dim partDoc As PartDocument = ThisDoc.Document

'Remove extension and adda suffix to the file path 
Dim fullFileName As String = Left(partDoc.FullFileName, Len(partDoc.FullFileName)-4) & "StartPart.ipt"
'MessageBox.Show(fullFileName, "Title")

partDoc.SaveAs(fullFileName, False)

iProperties.Value("Summary", "Subject") = referencePN

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 8

jmsantangelo61
Participant
Participant

If I set that rule up to run when the itrigger button is pressed, will it create the new document? So the user can press itrigger instead of save as? If so, that can work.

0 Likes
Message 4 of 8

A.Acheson
Mentor
Mentor

Sure you can manually trigger this how you like. You could use a global form also with a button for this rule. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 5 of 8

jmsantangelo61
Participant
Participant

Is it possible to add an input box to enter the new file name/part number instead of the current part number with start part? I tried to define a new variable as my entry in the input box command, but when I call for the new variable in the save as line it is failing.

0 Likes
Message 6 of 8

A.Acheson
Mentor
Mentor

Sure that would work, attach your attempt here and we see why it didn't work for you. 

If your testing comment out all lines of code for the save as portion of the code while you do your testing. Ensure you get a valid file file path in the message box. Once you do then do the save as. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 7 of 8

jmsantangelo61
Participant
Participant
Accepted solution

I actually figured out the code.  I will post below fyi.  I am struggling with the iTrigger now though. I coded trigger = iTrigger0 into the code after clicking the iTrigger button, as guided by autodesk's website, but when I click the iTrigger button again it does not run the rule.  It highlights the update button for a local update, and when I click that button all it does is add 1 to the iTrigger0 user parameter quantity.

 

trigger = Parameter("iTrigger0")
Dim referencePN As String = iProperties.Value("Project", "Part Number")
Dim partDoc As PartDocument = ThisDoc.Document
Dim newpartnumber As String = InputBox("Please Enter the New Part Number", "New Part Number", ThisDoc.FileName(False))
Dim fullfilename As String = ThisDoc.Path & "\" & newpartnumber & ".ipt"

partDoc.SaveAs(fullfilename, False)

iProperties.Value("Summary", "Subject") = referencePN
iProperties.Value("Project", "Part Number") = newpartnumber

 

0 Likes
Message 8 of 8

jmsantangelo61
Participant
Participant

After further research, I now understand that iTrigger only works for local rules, and therefore is not applicable in this situation.  However, I was able to add the rule as a button on the ribbon which is actually a better option in my opinion than using the iTrigger button.  Thank you for all your help.