Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
WCrihfield
in reply to: kwilson_design

Here is something you can try out.  I modified this from something I already had, in an attempt to suit your needs.  There are several ways to do something like this.

Sub Main
	Dim oDoc As Document = ThisDoc.FactoryDocument
	If oDoc Is Nothing OrElse ((Not TypeOf oDoc Is PartDocument) And (Not TypeOf oDoc Is AssemblyDocument)) Then
		MessageBox.Show("This code only works for a Part or Assembly.", "Wrong Document Type")
		Exit Sub
	End If
	If oDoc.IsModifiable = False Then Exit Sub
	'make sure the custom iProperty exists (then it will exist for all ModelStates)
	'first get a reference to the custom property set
	Dim oPNProp As Inventor.Property = oDoc.PropertySets.Item(3).Item("Part Number")
	Dim sPN As String 'this will hold the regular Part Number value later
	Dim oCProps As Inventor.PropertySet = oDoc.PropertySets.Item(4)
	'now create a variable to hold the custom property
	Dim oCProp As Inventor.Property = Nothing
	Try 'try to find existing one
		oCProp = oCProps.Item("Finished part number")
	Catch 'that failed, so create it
		oCProp = oCProps.Add("", "Finished part number")
	End Try
	If oCProp Is Nothing Then Exit Sub 'couldn't find or create the custom iProperty so exit rule
	Dim oMSs As ModelStates = oDoc.ComponentDefinition.ModelStates
	If oMSs.MemberEditScope <> MemberEditScopeEnum.kEditActiveMember Then
		oMSs.MemberEditScope = MemberEditScopeEnum.kEditActiveMember
	End If
	'make sure 'master/primary' ModelState is active, to get Part Number value from
	If oMSs.ActiveModelState IsNot oMSs.Item(1) Then
		oMSs.Item(1).Activate
	End If
	oDoc = oMSs.ActiveModelState.FactoryDocument
	sPN = oPNProp.Value
	Dim oNames() As String = {"-N", "-G", "L-N", "L-R", "R-N", "R-G" }
	For Each sName In oNames
		Dim oThisMS As ModelState = Nothing
		Try
			oThisMS = oMSs.Item(sName)
		Catch
			oThisMS = oMSs.Add(sName)
		End Try
		oThisMS.Activate
		oCProp.Value = sName
		oPNProp.Value = sPN & sName
	Next
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) :thumbs_up:.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)