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
Solved! Go to Solution.
Solved by james.collinsPWQR2. Go to Solution.
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
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.
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.