iLogic to create custom iproperty for current date with Hr min no seperators

iLogic to create custom iproperty for current date with Hr min no seperators

jonathan
Explorer Explorer
5,371 Views
6 Replies
Message 1 of 7

iLogic to create custom iproperty for current date with Hr min no seperators

jonathan
Explorer
Explorer

Hello Forum,

 

We are looking for help to create an iLogic rule that will be run manually.  This rule would create(if missing) a custom iproperty for current date(year/month/day) with hours and minutes directly after with no seperators. 

example: 2016-12-16 18:48  would create an iproperty: 201612161848

 

In the end we are wanting to use this iproperty on the end of a part number on an inventor drawing that will be added manually.

 

Any help would be much appreciated

 

Thank you

0 Likes
Accepted solutions (2)
5,372 Views
6 Replies
Replies (6)
Message 2 of 7

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi sharpj,

 

Here's an ilogic snippet that does what you're after.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

Dim Time As DateTime = DateTime.Now
Dim Format As String = "yyyyMdHHmm"

Dim oPropSet As PropertySet
oPropSet = _
ThisDoc.Document.PropertySets.Item("Inventor User Defined Properties")

Try
	'try to get the iproperty value
	oTest = iProperties.Value("Custom", "DateTimeString") 
Catch
	'catch error when iproperty doesn't exist and create it
	oPropSet.Add("", "DateTimeString")
End Try

'then set the property
iProperties.Value("Custom", "DateTimeString") = Time.ToString(Format)
Message 3 of 7

RasmusBredal
Advocate
Advocate
Accepted solution

@jonathanand if you want month and day to be shown with zero:

 

Dim Format As String = "yyyyMMddHHmm"

https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx

 

 

Message 4 of 7

jonathan
Explorer
Explorer

Perfect,

 

Would have been my next question.

 

Thank you

0 Likes
Message 5 of 7

jonathan
Explorer
Explorer

Hello Curtis,

 

Thank you for your quick post and an awesome ilogic snippet!

 

Message 6 of 7

hwu
Advocate
Advocate
Catch
	'catch error when iproperty doesn't exist and create it
	oPropSet.Add("", "DateTimeString")
End Try

'then set the property
iProperties.Value("Custom", "DateTimeString") = Time.ToString(Format)

Now it can be simplifed:

Catch

oPropSet.Add(Date.Now, "DateTimeString")

End Try

0 Likes
Message 7 of 7

Miguel.CarvajalS34Q6
Advocate
Advocate

thanks, but the code does not work, it must be some restiction that windows has

0 Likes