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: 

Is it possible to insert values fe the date independently?

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
Miguel.CarvajalS34Q6
233 Views, 3 Replies

Is it possible to insert values fe the date independently?

it is possible to insert in a drawing the date a model is generated, that is, the date the model is made. but it is necessary to separate the date; obtain the day, month and year separately, it is needed like this, to comply with a standard.
the variables should be like this example: 2023 - 01 - 15
year - month - day, but independent values. Thanks a lot

Labels (3)
3 REPLIES 3
Message 2 of 4

Hey Miguel.CarvajalS34Q6

Here's some code that i think will accomplish what you are after. When run from your drawing, it will look at the first view on the first sheet and get the model associated to that view. From there it will get the Date Create (Creation Time) iProperty from the model. It will then create four custom iProperties which you can then insert in your drawing as required.
If Not ThisApplication.ActiveDocument.DocumentType = kDrawingDocumentObject Then
	MessageBox.Show("This rule should only be run from Drawing files." & vbLf & _
	"Run rule only in .idw files!", "WARNING!", _
	MessageBoxButtons.OK, MessageBoxIcon.Warning)
	Exit Sub
End If
Dim docDrawing As DrawingDocument = ThisApplication.ActiveDocument		
fileNameWithPath = docDrawing.FullDocumentName
' Assuming there is a view on the first sheet
Dim sheetOne As Sheet = docDrawing.Sheets.Item(1)
Dim drawingView As DrawingView = sheetOne.DrawingViews.Item(1)
' Get the document that this view references
docViewModel = drawingView.ReferencedDocumentDescriptor.ReferencedDocument
Dim viewModelName As String = docViewModel.FullDocumentName
Dim dTPPropertySet As PropertySet = docViewModel.PropertySets.Item("Design Tracking Properties")  ' Inventor User Defined Properties
Dim uDPPropertySet As PropertySet = docViewModel.PropertySets.Item("Inventor User Defined Properties") ' Custom iProperties
Dim viewModelDateCreated As Inventor.Property = dTPPropertySet.Item("Creation Time")
Dim viewModelDateCreatedValue As Date = viewModelDateCreated.Value
MsgBox("Date Created Value: " & viewModelDateCreatedValue.ToString("yyyy - MM - dd"))
' Create these custom iProperties to store the Values that can then be inserted into the drawing as required
Dim viewModelDateCreatedYearMonthDay, viewModelDateCreatedYear, viewModelDateCreatedMonth, viewModelDateCreatedDay As Inventor.Property 
Try
	viewModelDateCreatedYear = uDPPropertySet.Add(viewModelDateCreatedValue.ToString("yyyy - MM - dd"), "ModelDateCreatedYearMonthDay")
Catch
	uDPPropertySet.Item("ModelDateCreatedYearMonthDay").Value = viewModelDateCreatedValue.ToString("yyyy - MM - dd")
End Try
Try
	viewModelDateCreatedYear = uDPPropertySet.Add(viewModelDateCreatedValue.ToString("yyyy"), "ModelDateCreatedYear")
Catch
	uDPPropertySet.Item("ModelDateCreatedYear").Value = viewModelDateCreatedValue.ToString("yyyy")
End Try
Try
	viewModelDateCreatedMonth = uDPPropertySet.Add(viewModelDateCreatedValue.ToString("MM"), "ModelDateCreatedMonth")
Catch
	uDPPropertySet.Item("ModelDateCreatedMonth").Value = viewModelDateCreatedValue.ToString("MM")
End Try
Try
	viewModelDateCreatedDay = uDPPropertySet.Add(viewModelDateCreatedValue.ToString("dd"), "ModelDateCreatedDay")
Catch
	uDPPropertySet.Item("ModelDateCreatedDay").Value = viewModelDateCreatedValue.ToString("dd")
End Try

Cheers,

 

James

Message 3 of 4

Just a quick tip to clean up the code a bit, the Date class has properties that will give you the year, month, and day without needing to convert to a string:

Dim todaysDate As Date = Date.Today
Dim year As string = todaysDate.Year
Dim month As string = todaysDate.Month
Dim day As string = todaysDate.Day

It also has other methods (like day of the year, day of the week, etc.) that could be useful as well.

Message 4 of 4

Thanks Zack, that looks a lot better. Here is the revised code:

 

If Not ThisApplication.ActiveDocument.DocumentType = kDrawingDocumentObject Then
	MessageBox.Show("This rule should only be run from Drawing files." & vbLf & _
	"Run rule only in .idw files!", "WARNING!", _
	MessageBoxButtons.OK, MessageBoxIcon.Warning)
	Exit Sub
End If
Dim docDrawing As DrawingDocument = ThisApplication.ActiveDocument		
fileNameWithPath = docDrawing.FullDocumentName
' Assuming there is a view on the first sheet
Dim sheetOne As Sheet = docDrawing.Sheets.Item(1)
Dim drawingView As DrawingView = sheetOne.DrawingViews.Item(1)
' Get the document that this view references
docViewModel = drawingView.ReferencedDocumentDescriptor.ReferencedDocument
Dim viewModelName As String = docViewModel.FullDocumentName
Dim dTPPropertySet As PropertySet = docViewModel.PropertySets.Item("Design Tracking Properties")  ' Inventor User Defined Properties
Dim uDPPropertySet As PropertySet = docViewModel.PropertySets.Item("Inventor User Defined Properties") ' Custom iProperties
Dim viewModelDateCreated As Inventor.Property = dTPPropertySet.Item("Creation Time")
Dim viewModelDateCreatedValue As Date = viewModelDateCreated.Value
Dim year As String = viewModelDateCreatedValue.Year
Dim month As String = viewModelDateCreatedValue.Month
Dim day As String = viewModelDateCreatedValue.Day
MsgBox("Date Created Value: " & year & " - " & month & " - " & day)
' Create these custom iProperties to store the Values that can then be inserted into the drawing as required
Dim viewModelDateCreatedYearMonthDay, viewModelDateCreatedYear, viewModelDateCreatedMonth, viewModelDateCreatedDay As Inventor.Property 
Try
	viewModelDateCreatedYear = uDPPropertySet.Add(year & " - " & month & " - " & day, "ModelDateCreatedYearMonthDay")
Catch
	uDPPropertySet.Item("ModelDateCreatedYearMonthDay").Value = year & " - " & month & " - " & day
End Try
Try
	viewModelDateCreatedYear = uDPPropertySet.Add(year, "ModelDateCreatedYear")
Catch
	uDPPropertySet.Item("ModelDateCreatedYear").Value = year
End Try
Try
	viewModelDateCreatedMonth = uDPPropertySet.Add(month, "ModelDateCreatedMonth")
Catch
	uDPPropertySet.Item("ModelDateCreatedMonth").Value = month
End Try
Try
	viewModelDateCreatedDay = uDPPropertySet.Add(day, "ModelDateCreatedDay")
Catch
	uDPPropertySet.Item("ModelDateCreatedDay").Value = day
End Try

Cheers,

 

James

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report