SETTING STOCK NUMBER VALUE BASED ON PARAMETERS

SETTING STOCK NUMBER VALUE BASED ON PARAMETERS

Keith.Challinor3761
Contributor Contributor
1,248 Views
9 Replies
Message 1 of 10

SETTING STOCK NUMBER VALUE BASED ON PARAMETERS

Keith.Challinor3761
Contributor
Contributor
The code below allows me to insert an ipt and set the parameters during insert, all works well 

in the code there is a portion to set the stock number based on the parameters , for some reason it sets the stock No to the ipt's original values not the ones stated during insert

can some one assist please as i need it to use the values set during insert



Dim
oAsm As AssemblyDocument = ThisDoc.Document Dim oPath As String = ThisDoc.Path If oPath = "" MessageBox.Show("Message", "Title", MessageBoxButtons.OK) End If Dim oCode As String = InputBox ("Code:W,S,OM,EX,", "Code","?") Dim oThickness As String = InputBox("Thickness:", "Thickness", "2") Dim oDia As String = InputBox("Diameter 80 - 400:", "Duct Diameter", "ENTER") Dim oLength As String = InputBox("Length:", "Length 500,1000,2000", "2000") Dim oFlange As String = InputBox("Flange:", "Flange", "6mm LIP") If System.IO.File.Exists(oPath & "\"& " Ø"& oDia & " Straight Duct" & " x " & oLength & "mm x " & oThickness & " Thick, " & oFlange & ".ipt") Then ThisApplication.CommandManager.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent, oPath & "\"& " Ø"& oDia & " Straight Duct" & " x " & oLength & "mm x " & oThickness & " Thick, " & oFlange & ".ipt") ThisApplication.CommandManager.ControlDefinitions.Item("AssemblyPlaceComponentCmd").Execute Else Dim oTemplate As String = "J:\Inventor Library\Ducting\JKF_DUCT.ipt" Dim pDoc As PartDocument = ThisApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject, oTemplate, False) pDoc.ComponentDefinition.Parameters.Item("DIA").Expression = oDia pDoc.ComponentDefinition.Parameters.Item("Length").Expression = oLength pDoc.ComponentDefinition.Parameters.Item("Thickness").Expression = oThickness pDoc.Update ThisApplication.UserInterfaceManager.DoEvents iProperties.Value("Project", "Stock Number")= ("oCode" &"/"& "oDIA" & "/" &"oLength") pDoc.SaveAs(oPath & "\" & " Ø"& oDia & " Straight Duct" & " x " & oLength & "mm x " & oThickness & " Thick, " & oFlange & ".ipt", False) pDoc.Close ThisApplication.CommandManager.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent,oPath & "\"& " Ø"& oDia & " Straight Duct" & " x " & oLength & "mm x " & oThickness & " Thick, " & oFlange & ".ipt") ThisApplication.CommandManager.ControlDefinitions.Item("AssemblyPlaceComponentCmd").Execute End If oAsm.Update

 

0 Likes
Accepted solutions (2)
1,249 Views
9 Replies
Replies (9)
Message 2 of 10

WCrihfield
Mentor
Mentor

Are you wanting that "Stock Number" property's value to be based on your InputBox values directly, or are you trying to get it to contain live references to custom iProperties, which are linked to 'exposed' Parameters?

The location of your 'DoEvents' line doesn't seem right.  It seems that line should be right after each of the PostPrivateEvent lines.  Maybe try changing that around, and see if it fixes anything.  Which scenario is it happening in, the preexisting part file, or the 'new' part file?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 10

Ralf_Krieg
Advisor
Advisor

Hello

 

Why do you set all of the input variables in double quotes?

iProperties.Value("Project", "Stock Number")= ("oCode" &"/"& "oDIA" & "/" &"oLength")

 The result should be the String "oCode/oDIA/oLength" which is surely not what you want. Could you try instead

iProperties.Value("Project", "Stock Number")= oCode & "/" & oDIA & "/" & oLength

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 4 of 10

Keith.Challinor3761
Contributor
Contributor

Thanks for the reply 

 

i have tried what has been suggested by all but to little  success

 

the part created in the assembly refuses to have the stock number set to the parameter values stated during its creation 

when i have got it to work it will update the dia and length but not the code the code stays set to what was stated in the original template ipt 

 

still open to suggestions before i through it all in the bin 😉

0 Likes
Message 5 of 10

Ralf_Krieg
Advisor
Advisor

Hello

 

In addition to the hint I gave you above, in the same line the command did not write the iProperty to your part, but to the assembly the part is placed in.

 

iProperties.Value("Project", "Stock Number")= ("oCode" &"/"& "oDIA" & "/" &"oLength")

 

 

Please try

 

Dim oAsm As AssemblyDocument = ThisDoc.Document 
Dim oPath As String = ThisDoc.Path 
If oPath = "" 
	MessageBox.Show("Message", "Title", MessageBoxButtons.OK)
End If
Dim oCode As String = InputBox ("Code:W,S,OM,EX,", "Code","?") 
Dim oThickness As String = InputBox("Thickness:", "Thickness", "2") 
Dim oDia As String = InputBox("Diameter 80 - 400:", "Duct Diameter", "ENTER")  
Dim oLength As String = InputBox("Length:", "Length 500,1000,2000", "2000") 
Dim oFlange As String = InputBox("Flange:", "Flange", "6mm LIP")
If System.IO.File.Exists(oPath & "\" & " Ø" & oDia & " Straight Duct" & " x " & oLength & "mm x " & oThickness & " Thick, " & oFlange & ".ipt") Then
	ThisApplication.CommandManager.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent, oPath & "\"& " Ø"& oDia & " Straight Duct" & " x " & oLength & "mm x " & oThickness & " Thick, " & oFlange & ".ipt") 
	ThisApplication.CommandManager.ControlDefinitions.Item("AssemblyPlaceComponentCmd").Execute 
Else 
	Dim oTemplate As String = "J:\Inventor Library\Ducting\JKF_DUCT.ipt" 
	Dim pDoc As PartDocument = ThisApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject, oTemplate, False)  
	pDoc.ComponentDefinition.Parameters.Item("DIA").Expression = oDia
	pDoc.ComponentDefinition.Parameters.Item("Length").Expression = oLength
	pDoc.ComponentDefinition.Parameters.Item("Thickness").Expression = oThickness 
	pDoc.Update 
	pDoc.PropertySets("{32853F0F-3444-11D1-9E93-0060B03C1CA6}").Item("Stock Number").Value  = (oCode & "/" & oDia & "/" & oLength)
	pDoc.SaveAs(oPath & "\" & " Ø"& oDia & " Straight Duct" & " x " & oLength & "mm x " & oThickness & " Thick, " & oFlange & ".ipt", False) 
	pDoc.Close 
	ThisApplication.CommandManager.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent,oPath & "\"& " Ø"& oDia & " Straight Duct" & " x " & oLength & "mm x " & oThickness & " Thick, " & oFlange & ".ipt")
    ThisApplication.CommandManager.ControlDefinitions.Item("AssemblyPlaceComponentCmd").Execute 
End If 
oAsm.Update 

 

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 6 of 10

WCrihfield
Mentor
Mentor
Accepted solution

I got thinking about this later while I was working on something else, and the thought came up that the iProperties.Value() call may not be working for you, because that part that you just created 'invisibly' may not be the 'active' document at that moment, and that call works with the 'active' document.  So you would have to write that iProperty to that part using the longer route.  So I revisited this post with this update, and moved a couple other things around too.  Here's what I came up with.  See if this works any better.

 

Dim oAsm As AssemblyDocument = ThisDoc.Document
Dim oPath As String = ThisDoc.Path 
If oPath = "" 
	MsgBox("The 'Path' of the assembly is empty. Exiting.", , "")
	Exit Sub
End If

Dim oCode As String = InputBox ("Code:W,S,OM,EX,", "Code","?") 
Dim oThickness As String = InputBox("Thickness:", "Thickness", "2") 
Dim oDia As String = InputBox("Diameter 80 - 400:", "Duct Diameter", "ENTER")  
Dim oLength As String = InputBox("Length:", "Length 500,1000,2000", "2000") 
Dim oFlange As String = InputBox("Flange:", "Flange", "6mm LIP")
Dim oFName As String = oPath & "\" & " Ø"& oDia & " Straight Duct" & " x " & oLength & "mm x " & oThickness & " Thick, " & oFlange & ".ipt"

Dim oCM As CommandManager = ThisApplication.CommandManager

If Not System.IO.File.Exists(oFName) Then
	Dim oTemplate As String = "J:\Inventor Library\Ducting\JKF_DUCT.ipt" 
	Dim pDoc As PartDocument = ThisApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject, oTemplate, False)
	Dim oParams As Parameters = pDoc.ComponentDefinition.Parameters
	oParams.Item("DIA").Expression = oDia
	oParams.Item("Length").Expression = oLength
	oParams.Item("Thickness").Expression = oThickness 
	pDoc.Update
	'since you created the Part invisibly, it might not be the 'active' document, and the iProperties.Value() call acts on the 'active' document
	'so we'll set this parts iProperty this way, instead, to be sure
	pDoc.PropertySets.Item("Design Tracking Properties").Item("Stock Number").Value = oCode & "/" & oDia & "/" & oLength
	pDoc.SaveAs(oFName, False) 
	pDoc.Close 
End If 
oCM.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent, oFName)
ThisApplication.UserInterfaceManager.DoEvents
oCM.ControlDefinitions.Item("AssemblyPlaceComponentCmd").Execute 
oAsm.Update

 

Oops. Looks like we were both working on this at the same time and @Ralf_Krieg posted something similar first.

 

 

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

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 7 of 10

Keith.Challinor3761
Contributor
Contributor
Krieg

I appreciate the efforts unfortunately the latest didn't work , the Ø value and the length updated and were entered into the stock number but the code fails to update the letter stays as stated in the template IPT
0 Likes
Message 8 of 10

Keith.Challinor3761
Contributor
Contributor
WCrihfield
Sorry to report this doesn't work either , I truly appreciate all the efforts being put into this but am beginning to feel it isn't possible ( deep down the must be a way )
Is it because the code is text ?
As the numeric inputs for dia and length work OK
Keith

0 Likes
Message 9 of 10

WCrihfield
Mentor
Mentor

Well, setting a parameters 'Expression' definitely works differently than setting its 'Value', but can sometimes be more stable that way.  When setting the expression (as a simple value, not an equation), it is understood as literal, and doesn't attempt to convert its units, but when you set the value of a numeric parameter with a simple numeric value, it will by default get converted (understood as 'database' units), which causes a lot of folks problems.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 10 of 10

Ralf_Krieg
Advisor
Advisor
Accepted solution

Hello

 

You're right, the text parameter needs extra quotes. I forgot, sorry. Edit the line to

pDoc.ComponentDefinition.Parameters.Item("Code").Expression = Chr(34) & oCode & Chr(34)

 


R. Krieg
RKW Solutions
www.rkw-solutions.com