I am not a programmer and I am using ChatGPT to create this

I am not a programmer and I am using ChatGPT to create this

nathan_m_gardner
Enthusiast Enthusiast
429 Views
4 Replies
Message 1 of 5

I am not a programmer and I am using ChatGPT to create this

nathan_m_gardner
Enthusiast
Enthusiast

Let me start off with, Thank you for your help. As I said, I am not a coder. I wish I could write code but I do not have the training or the work to keep the coding fresh in my mind. I did take one basic C# class ten years ago. Nothing before and nothing since. 

 

I am working on a macro to help speed up the process of signing off drawings. I have everything working now except for one field that is not updating. The code is not erroring out. The field is not changing. 

 

These are the fields within the iProperties of a DWG file. I am trying to set the "Eng. Approved By" field on the status tab. Below is my code for this section. I have given a screenshot of the title block callout and the iProperties<status tab.

 

nathan_m_gardner_1-1744809007259.png

 

 

0 Likes
Accepted solutions (2)
430 Views
4 Replies
Replies (4)
Message 2 of 5

Stakin
Collaborator
Collaborator
Accepted solution

modify "Eng Approved By" to "Engr Approved By" ,try again

0 Likes
Message 3 of 5

nathan_m_gardner
Enthusiast
Enthusiast

Thank you

0 Likes
Message 4 of 5

nathan_m_gardner
Enthusiast
Enthusiast

Thanks again Stakin,

 

Would you be able to help me with this new section of the code? I have added the option to set the date as well. The user has three options. If you can't help I will post it. Thanks either way!

 

"msg = "What would you like to do for '" & propName & "'?" & vbCrLf & _
"1 - Set to today's date (" & todayStr & ")" & vbCrLf & _
"2 - Leave existing date as-is" & vbCrLf & _
"3 - Enter a new date (use your computer's format: " & todayStr & ")""

 

The code runs and allows you to choose any of the three options and finishes up without error. It just does not change the dates. 

 

How can I find the names of items like this? Is there a tool that allows me to watch the commands and how they execute within Inventor?

 

 

 

Sub Tb_Fill()
Dim oDoc As Document
Dim dwg_rev As String, ckr As String, apr As String, drn As String
Dim currentRev As String, currentCkr As String, currentApr As String, currentAuthor As String, currentDesigner As String
Dim propSetSummary As PropertySet, propSetTracking As PropertySet, propSetCustom As PropertySet
Dim localDate As String: localDate = Format(Date, "Short Date")

' Ensure an active document is open
If ThisApplication.ActiveDocument Is Nothing Then
MsgBox "No active document open!", vbExclamation, "Error"
Exit Sub
End If

Set oDoc = ThisApplication.ActiveDocument

' Ensure it's a drawing document
If oDoc.DocumentType <> kDrawingDocumentObject Then
MsgBox "Active document is not a drawing file!", vbExclamation, "Error"
Exit Sub
End If

' Get property sets
On Error Resume Next
Set propSetSummary = oDoc.PropertySets.Item("Inventor Summary Information")
Set propSetTracking = oDoc.PropertySets.Item("Design Tracking Properties")
Set propSetCustom = oDoc.PropertySets.Item("Inventor User Defined Properties")
On Error GoTo 0

If propSetSummary Is Nothing Or propSetTracking Is Nothing Or propSetCustom Is Nothing Then
MsgBox "Unable to access required property sets.", vbCritical, "Error"
Exit Sub
End If

' Get current values
On Error Resume Next
currentRev = propSetSummary.Item("Revision Number").Value
currentAuthor = propSetSummary.Item("Author").Value
currentDesigner = propSetTracking.Item("Designer").Value
currentCkr = propSetTracking.Item("Checked By").Value
currentApr = propSetTracking.Item("Engr Approved By").Value
On Error GoTo 0

' Prompt inputs
dwg_rev = Trim(InputBox("Enter Revision Number (leave blank to skip):", "Revision", currentRev))
If dwg_rev <> "" Then
SetOrAdd propSetSummary, "Revision Number", dwg_rev
' No date prompt for revision
End If

drn = Trim(InputBox("Enter Author/Designer Name (leave blank to skip):", "Author/Designer", currentAuthor))
If drn <> "" Then
SetOrAdd propSetSummary, "Author", drn
SetOrAdd propSetTracking, "Designer", drn
HandleDatePrompt propSetCustom, "Creation Date", localDate
End If

ckr = Trim(InputBox("Enter Checker Name (leave blank to skip):", "Checker", currentCkr))
If ckr <> "" Then
SetOrAdd propSetTracking, "Checked By", ckr
HandleDatePrompt propSetCustom, "checked date", localDate
End If

apr = Trim(InputBox("Enter Approver Name (leave blank to skip):", "Approver", currentApr))
If apr <> "" Then
SetOrAdd propSetTracking, "Engr Approved By", apr
HandleDatePrompt propSetCustom, "Engr Approved Date", localDate
End If

MsgBox "iProperties updated (only filled fields).", vbInformation, "Done"
End Sub

Sub SetOrAdd(propSet As PropertySet, propName As String, val As String)
On Error Resume Next
propSet.Item(propName).Value = val
If Err.Number <> 0 Then
Err.Clear
propSet.Add val, propName
End If
On Error GoTo 0
End Sub

Sub HandleDatePrompt(propSet As PropertySet, propName As String, todayStr As String)
Dim msg As String
Dim response As String
Dim newDate As String

msg = "What would you like to do for '" & propName & "'?" & vbCrLf & _
"1 - Set to today's date (" & todayStr & ")" & vbCrLf & _
"2 - Leave existing date as-is" & vbCrLf & _
"3 - Enter a new date (use your computer's format: " & todayStr & ")"

response = InputBox(msg, "Date Option", "1")

Select Case Trim(response)
Case "1"
SetOrAdd propSet, propName, todayStr
Case "3"
newDate = InputBox("Enter the new date for '" & propName & "':", "Manual Date", todayStr)
If newDate <> "" Then
SetOrAdd propSet, propName, newDate
End If
Case Else
' Do nothing (option 2 or invalid input)
End Select
End Sub

0 Likes
Message 5 of 5

Stakin
Collaborator
Collaborator
Accepted solution

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

Sub Tb_Fill()
Dim oDoc As Document
Dim dwg_rev As String, ckr As String, apr As String, drn As String
Dim currentRev As String, currentCkr As String, currentApr As String, currentAuthor As String, currentDesigner As String
Dim propSetSummary As PropertySet, propSetTracking As PropertySet, propSetCustom As PropertySet
Dim localDate As String: localDate = Format(Date, "Short Date")

' Ensure an active document is open
If ThisApplication.ActiveDocument Is Nothing Then
MsgBox "No active document open!", vbExclamation, "Error"
Exit Sub
End If

Set oDoc = ThisApplication.ActiveDocument

' Ensure it's a drawing document
If oDoc.DocumentType <> kDrawingDocumentObject Then
MsgBox "Active document is not a drawing file!", vbExclamation, "Error"
Exit Sub
End If

' Get property sets
On Error Resume Next
Set propSetSummary = oDoc.PropertySets.Item("Inventor Summary Information")
Set propSetTracking = oDoc.PropertySets.Item("Design Tracking Properties")
Set propSetCustom = oDoc.PropertySets.Item("Inventor User Defined Properties")
On Error GoTo 0

If propSetSummary Is Nothing Or propSetTracking Is Nothing Or propSetCustom Is Nothing Then
MsgBox "Unable to access required property sets.", vbCritical, "Error"
Exit Sub
End If

' Get current values
On Error Resume Next
currentRev = propSetSummary.Item("Revision Number").Value
currentAuthor = propSetSummary.Item("Author").Value
currentDesigner = propSetTracking.Item("Designer").Value
currentCkr = propSetTracking.Item("Checked By").Value
currentApr = propSetTracking.Item("Engr Approved By").Value
On Error GoTo 0

' Prompt inputs
dwg_rev = Trim(InputBox("Enter Revision Number (leave blank to skip):", "Revision", currentRev))
If dwg_rev <> "" Then
SetOrAdd propSetSummary, "Revision Number", dwg_rev
' No date prompt for revision
End If

drn = Trim(InputBox("Enter Author/Designer Name (leave blank to skip):", "Author/Designer", currentAuthor))
If drn <> "" Then
SetOrAdd propSetSummary, "Author", drn
SetOrAdd propSetTracking, "Designer", drn
HandleDatePrompt  propSetTracking, "Creation Time", localDate
End If

ckr = Trim(InputBox("Enter Checker Name (leave blank to skip):", "Checker", currentCkr))
If ckr <> "" Then
SetOrAdd propSetTracking, "Checked By", ckr
HandleDatePrompt  propSetTracking, "Date Checked", localDate
End If

apr = Trim(InputBox("Enter Approver Name (leave blank to skip):", "Approver", currentApr))
If apr <> "" Then
SetOrAdd propSetTracking, "Engr Approved By", apr
HandleDatePrompt  propSetTracking, "Engr Date Approved", localDate
End If

MsgBox "iProperties updated (only filled fields).", vbInformation, "Done"
End Sub

Sub SetOrAdd(propSet As PropertySet, propName As String, val As String)
On Error Resume Next
propSet.Item(propName).Value = val
If Err.Number <> 0 Then
Err.Clear
propSet.Add val, propName
End If
On Error GoTo 0
End Sub

Sub HandleDatePrompt(propSet As PropertySet, propName As String, todayStr As String)
Dim msg As String
Dim response As String
Dim newDate As String

msg = "What would you like to do for '" & propName & "'?" & vbCrLf & _
"1 - Set to today's date (" & todayStr & ")" & vbCrLf & _
"2 - Leave existing date as-is" & vbCrLf & _
"3 - Enter a new date (use your computer's format: " & todayStr & ")"

response = InputBox(msg, "Date Option", "1")

Select Case Trim(response)
Case "1"
SetOrAdd propSet, propName, todayStr
Case "3"
newDate = InputBox("Enter the new date for '" & propName & "':", "Manual Date", todayStr)
If newDate <> "" Then
SetOrAdd propSet, propName, newDate
End If
Case Else
' Do nothing (option 2 or invalid input)
End Select
End Sub

Report

 

You can get the ipropertes' Name or Id from attsched file.  You just add three user defined properties of "Creation Date" "Engr Approved Date"checked date",Instead of modifying the properties that come with the system,you can check in custom tag of iproperties form.