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: 

Last export date

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
t.office
332 Views, 9 Replies

Last export date

Hello, is it possible to have an ilogic that runes before a file is exported as .dwg, that updates the date.

 

My objective is to have in the title block of the exported .dwg the date in which it was exported.

 

 

toffice_0-1697651540561.png

 

9 REPLIES 9
Message 2 of 10
WCrihfield
in reply to: t.office

Hi @t.office.  That does sound possible.  However, we would need to know more about the title block you are showing.  It looks like it does not currently have any date showing in it.  Are you currently using a 'prompted entry' to fill that in?  Or do you maybe have a custom iProperty linked to the TextBox behind that location in your title box?  If you do not have an iProperty linked to that position, then we would have to find which specific TextBox object within the sketch of your title block definition is being used to show that date.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 10
t.office
in reply to: WCrihfield

I currently have the creation date iProperties, i was thinking of updating that.
 
Below you can find the .idw
Message 4 of 10
WCrihfield
in reply to: t.office

OK.  I see now.  That is usually the easiest to deal with.  However, after inspecting your drawing's title block, and editing that specific TextBox, the Format Text dialog indicates that it is liked to the creation date iProperty of the 'model' document, instead of the drawing itself.  In a case like that, we would need to get a reference to the 'model' document first, then access its creation date iProperty, then set it to todays date.  But if that is a different value than it was before, we may have to first record the original date, then change it, then set the original date back to it, so we don't change the model in an unwanted way.  Here is an iLogic rule code to access that iProperty of the drawing's model.

'third PropertySet InternalName = {32853F0F-3444-11d1-9E93-0060B03C1CA6}
'Creation Date Property is first Index in PropertySet, or use ItemByPropID(4) 
Dim oCDateProp As Inventor.Property = ThisDrawing.ModelDocument.PropertySets.Item(3).Item(1)
Dim OriginalDate As Date = oCDateProp.Value
oCDateProp.Value = Today
'<<< now export the drawing with some code here >>>
'<<< now set original date back to model >>>
oCDateProp.Value = OriginalDate

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 10
t.office
in reply to: WCrihfield

Sorry that was a mistake, i have changed the link to the drawing date iProperty, i would much rather not involve the linked part.

 

Is it possible to have the rule run automatically before the file is exported?

Message 6 of 10
WCrihfield
in reply to: t.office

I'm on my way out for the day, so I have not downloaded your edited drawing yet, but the quick answer is yes.  If you will be exporting the drawing by code, you can put this code just before the code to export the file.  But if exporting manually, there may not be a way to completely automate it to update the creation date just before it exports.  You could either change it manually through the iProperties dialog, or manually run the rule to change it.  I am not sure if putting that small iLogic rule under the 'Before Save Document' event in the This Document tab of the Event Triggers dialog would work if exporting, and not just saving the document.  I may look into this more tomorrow.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 7 of 10
t.office
in reply to: WCrihfield

thank you that would be great.

Message 8 of 10
WCrihfield
in reply to: t.office

Hi @t.office.  I think I have figured out a way to make this happen for you.  In your original post, you mentioned that you are exporting something to a DWG file type.  I assume the 'original' file that you are exporting from is a regular Inventor IDW drawing file, correct?  If that is not correct, then the solution I am providing here may not work for you without further modifications.  This iLogic rule solution is a rather complex one.  After you run this rule, it will create and launch a custom event handler that will remain running in the background, listening for the event of 'translating a document', until you close Inventor.  When this event is triggered, this block of code has to check several things about the event before it will react to it, because it covers a lot of different types of import / export operations and file types.  If the event is for importing, instead of exporting, it will not do anything else.  If the 'original' file's name does not end with ".idw", it will not do anything else.  If the file name of the resulting file it is about to create does not end with ".dwg", it will not do anything else.  If it passes all those tests, it must be for exporting an IDW file to a DWG file.  Then it attempts to open that original drawing invisibly (in the background), then checks its Creation Date iProperty against today's date, and only if it does not match, it will try to change it to todays date.  Then it will attempt to update the drawing.  Then it will attempt to save the drawing again.  Then, if it did that, it will write a message to the iLogic Log window about it.  All that code so far will only run just 'before' the file is exported, not afterwards.  Then I left some code in the 'After' side of the event that just writes something to the iLogic Log window after the event.  But that 'After' part will be carried out for all import or export operations.  If you do not want that part, you can either comment it out, or delete it (just don't delete the final 'End If' line before the 'End Sub' line.

 

Caution:  I have not tested this code yet, so if you run it, and it is not functioning correctly, you may need to close Inventor, then restart Inventor, to get rid of the event handler it creates.

 

Sub Main
	oAppEvents = ThisApplication.ApplicationEvents
	AddHandler oAppEvents.OnTranslateDocument, AddressOf oAppEvents_OnTranslateDocument
End Sub

Dim oAppEvents As Inventor.ApplicationEvents

Sub oAppEvents_OnTranslateDocument(TranslatingIn As Boolean, DocumentObject As Document, _
FullFileName As String, BeforeOrAfter As EventTimingEnum, Context As NameValueMap, _
ByRef HandlingCode As HandlingCodeEnum)
	If BeforeOrAfter = EventTimingEnum.kBefore Then
		If TranslatingIn = True Then Exit Sub 'we only want to respond when exporting (translating out)
		If FullFileName.EndsWith(".idw") = False Then Exit Sub 'FullFileName is for the 'original' file
		If Context.Count = 0 Then Exit Sub 'if no Context to review, exit routine
		Dim TargetData As Inventor.DataMedium = Nothing
		Try : TargetData = Context.Value("TargetData") : Catch : End Try
		If TargetData Is Nothing Then Exit Sub
		If TargetData.MediumType = MediumTypeEnum.kFileNameMedium Then
			Dim sDestinationFullFileName As String = TargetData.FileName
			If sDestinationFullFileName.EndsWith(".dwg") Then 'check if exporting to a DWG file type
				Dim oDDoc As DrawingDocument = Nothing
				Try : oDDoc = ThisApplication.Documents.Open(FullFileName, False) : Catch : End Try
				If oDDoc Is Nothing Then Exit Sub
				Dim oCDateProp As Inventor.Property = oDDoc.PropertySets.Item(3).Item(1)
				If oCDateProp.Value <> Today Then
					Try : oCDateProp.Value = Today : Catch : End Try
					If oDDoc.RequiresUpdate Then Try : oDDoc.Update2(True) : Catch : End Try
					If oDDoc.Dirty Then Try : oDDoc.Save2(False) : Catch : End Try
				End If
				Try : oDDoc.ReleaseReference : Catch : End Try
				Logger.Info("Checked / Updated Creation Date of following IDW file before export to DWG file:"& vbCrLf & FullFileName)
			End If
		End If
	ElseIf BeforeOrAfter = EventTimingEnum.kAfter Then
		If DocumentObject IsNot Nothing Then
			Logger.Info(FullFileName & vbCrLf & "...was just translated to:" & vbCrLf & DocumentObject.FullFileName)
		End If
	End If
End Sub

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 9 of 10
t.office
in reply to: WCrihfield

I was thinking, wouldn't it be easier to just have a rule that updates the date which is triggered when the file is opened, sorry for the wild-goose chase.

 

I tried cutting the part that updates the date from your rule but I keep getting an error.

Message 10 of 10
WCrihfield
in reply to: t.office

If you just want some simple code for an internal iLogic rule that will be triggered by the document open event, then you could use the following.

Dim oDoc As Document = ThisDoc.Document
Dim oCreationDateProp As Inventor.Property = oDoc.PropertySets.Item(3).Item(1)
If oCreationDateProp.Value <> Today Then oCreationDateProp.Value = Today
If oDoc.RequiresUpdate Then oDoc.Update2(True)

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

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

Post to forums  

Autodesk Design & Make Report