ModelParameterObject in API

ModelParameterObject in API

breinkemeyer
Enthusiast Enthusiast
397 Views
2 Replies
Message 1 of 3

ModelParameterObject in API

breinkemeyer
Enthusiast
Enthusiast

I'm doing some C# to some model customization.  In the ModelParameters Object there is supposed to be an "Item" property as per the documentation.  Using VS2017 and have added the Inventor reference.  as a workaround I'm looping through, but that seems odd,.  code is below.

 

 

 

// start with the pipe file
System.IO.File.Copy(sTemplatePath + "Pipe.ipt", ProjectPath + "Pipe_" + sFileName + ".ipt");
Ready = false;
cSE.oIPartDoc = (PartDocument)cSE.oIDocs.Open(ProjectPath + "Pipe_" + sFileName + ".ipt");
if (!Ready)
{
Thread.Sleep(250);
}

//now update the parameters
cSE.oIPartCompDef = cSE.oIPartDoc.ComponentDefinition;
cSE.oIModelParameters = cSE.oIPartDoc.ComponentDefinition.Parameters.ModelParameters;
foreach (ModelParameter modelParameter in cSE.oIModelParameters)
{
string name = modelParameter.Name;
switch (name)
{
case "Length":
modelParameter.Value = dScrewLength * cSE.IV;
break;
case "OutsideDia":
modelParameter.Value = dPipeOD * cSE.IV;
break;
case "InsideDia":
modelParameter.Value = dPipeID * cSE.IV;
break;
}
}
cSE.oIPartDoc.Update();

0 Likes
Accepted solutions (1)
398 Views
2 Replies
Replies (2)
Message 2 of 3

YuhanZhang
Autodesk
Autodesk
Accepted solution

In C#, you can also get a ModelParameter using its name as index, but not like in VB.net it does not use it like ModelParameters.Item("Length"), it just uses below format:

 

modelParam = ModelParameters.["Length"]; 

This also applies to other cases if you want to get an item from a collection object in C#. Hope this clears.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes
Message 3 of 3

breinkemeyer
Enthusiast
Enthusiast

Thank you sir!  works perfect.

0 Likes