unable to set value for parameter in DirectShape

unable to set value for parameter in DirectShape

Anonymous
Not applicable
1,069 Views
2 Replies
Message 1 of 3

unable to set value for parameter in DirectShape

Anonymous
Not applicable
unable to set value for parameter in DirectShape

Hi;

I am trying to set value for one parameter which binding with Generic category( DirectShape) . and generate (PROCESS:1-BIN .

But setting value returned false. 

 

Thanks,

my code: 

 

using(TransactionGroup transGroup = new TransactionGroup(doc))
{
using(Transaction trans = new Transaction(doc))
{
transGroup.Start("Action");

trans.Start("SharedParam");

ProjectConstant con = new ProjectConstant(0,1,2,3,4,5,6,7,8,9,10,11);
var one = new One();
List<List<Curve>> Lines = one.Getlines(doc,linestylesA,linestylesB,option);
List<Curve> curvesParent = Lines.ElementAt(0) as List<Curve>;
List<Curve> curveMain = Lines.ElementAt(1) as List<Curve>;
SketchPlane sketchPlane = one.GetPlane(doc,curveMain,iResult);
one.ListPointDicUnfinished(curveMain,curveMain,doc,sketchPlane,linestylesB,pointsPropertiesALL,curveremoving,iResult);
one.ListPointDicUnfinished(curvesParent,curveMain,doc,sketchPlane,linestylesB,pointsPropertiesALL,curveremoving,iResult);
foreach(Curve B in curveremoving)
{
doc.Delete(B.Reference.ElementId);
}
List<IDictionary<int,object>> ONEpointsALLines = one.ListPointDictionary(pointsPropertiesALL);

///STEP 1 : CREATING SOLID GEOMETRY AND BINDING THE SHARED PARAMETER WITH GENERIC CATEGORY IF IT DOESNT HAVE IT ALREADY.
List<Solid> solids = one.GetSolids(ONEpointsALLines).ElementAt(0).ConvertAll(x => x as Solid);
var createshareParam = new Share();
Definition tt = createshareParam.Main(doc,_filename,_groupname,_defname,_deftype,targets);

///STEP 2 : CREATE DIRECT SHAPE
if(trans.Commit() != TransactionStatus.Committed)
{
return Result.Failed;
}
trans.Start("DirectShape");
List<ElementId> ListElementId = new List<ElementId> { };
for(int i = 0; i < solids.Count; i++)
{
List<GeometryObject> geo = new List<GeometryObject> { solids.ElementAt(i) as GeometryObject };
DirectShape ds = DirectShape.CreateElement(doc,new ElementId(BuiltInCategory.OST_GenericModel));
ds.GetOptions().ReferencingOption = DirectShapeReferencingOption.Referenceable;
ds.ApplicationId = "aplication id";
ds.ApplicationDataId = "geometry object id";
ds.SetShape(geo);
ds.SetName("MyShape" + i.ToString());
bool ll = ds.get_Parameter(tt).SetValueString(linestylesB);
ElementId IdDirectShape = ds.Id;
ListElementId.Add(IdDirectShape);
}
doc.Regenerate();

///STEP 3 : SETTING VALUE FOR PARAMETER IN DIRECT SHAPE
if(trans.Commit() != TransactionStatus.Committed)
{
return Result.Failed;
}
trans.Start("values");
foreach(ElementId elmentId in ListElementId)
{
Element directshape = doc.GetElement(elmentId);
bool rr = directshape.get_Parameter(tt as Definition).SetValueString(linestylesB);
}
if(trans.Commit() != TransactionStatus.Committed)
{
return Result.Failed;
}
transGroup.Assimilate();
}
return Result.Succeeded;
}

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

RPTHOMAS108
Mentor
Mentor
Accepted solution

Don't use .SetValueString

 

"This method only applies to parameters of value types."

 

For the parameter in question lookup the storage type and use either:

Parameter.Set(ElementID), Parameter.Set(Double), Parameter.Set(Integer), Parameter.Set(String)

Message 3 of 3

Anonymous
Not applicable
Accepted solution

Thanks! it worked.

0 Likes