CreateFromRebarShape Method with different shape size

CreateFromRebarShape Method with different shape size

atir5UTNF
Advocate Advocate
364 Views
5 Replies
Message 1 of 6

CreateFromRebarShape Method with different shape size

atir5UTNF
Advocate
Advocate

I want to create round stirrup using the default round shape stirrup "M_T3" with different radius.

The problam is that "create" method uses the default shape bounding box to palce at the origin, but I can't change the radius before I have the stirrup.

I tried to change "roundStirrupRebarShape" radius before calling "create", but it throw an Exception "Read Only parameter".

What is the right way to use this mathod?

 

 

 

org = XYZ.Zero;
xVect = XYZ.BasisX;
yVect = XYZ.BasisY;

Rebar roundStirrup = Rebar.CreateFromRebarShape(rvtDoc,roundStirrupRebarShape, rebarBarType,column, org,xVect,yVect);

//code added before pic 2:
ParameterMap parametersMap = roundStirrup.ParametersMap;
Parameter radiusParam = parametersMap.get_Item("R");
double radius = 32.5 * rvt_cm;  //rvt_cm = 0.0328083....[ft]
radiusParam.Set(radius);

 

 

roundStirrup.jpg

 

0 Likes
365 Views
5 Replies
Replies (5)
Message 2 of 6

jeremy_tammik
Alumni
Alumni

The parameter value cannot be edited before you create the rebar because the parameter itself doesn't exist beforehand. It is just a double value that needs to be stored in the appropriate structure on an existing element. So, you have to create the rebar first, then you can change its parameters. The rebar will be created using the default parameter values.

    

Alternatively, you may be able to change the parameter values on the rebar type beforehand, i.e., set the radius on the type before creating the rebar instance. The rebar may take the modified rebar type parameter value as the default.

 

Please let us know how it works out for you. Thank you!

 

Best regards from George and Jeremy, side by side in Nairobi, Kenya.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 6

atir5UTNF
Advocate
Advocate

Hey Jeremy,

So way ask me to give "org", xVec" and "yVect"?
These parameters are useless, since I will allways need to transform the created rebar to the place I want.

 

I'm not sure I understand the suggested alternative way.
My bar type is set to 8 mm diameter.
I want the stirrup's shape to be a circle with R = 32.5 cm.

 

Thanks!

0 Likes
Message 4 of 6

jeremy_tammik
Alumni
Alumni

Sorry, indeed; in that case, you cannot affect the result with the rebar type. My mistake.

  

So, pic 2 is the desired result? And the code snippet that you share generates the desired result? Well, then I would suggest using it like that, and calling create before trying to set the parameter. As said, there exists no parameter to set until after the creation has taken place. So, if the code snippet you show works, I see no other solution to this task.

  

If there is a problem setting the parameter after calling create, adding a call in between create and set parameter to regenerate might help:

 

https://thebuildingcoder.typepad.com/blog/about-the-author.html#5.33

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 5 of 6

atir5UTNF
Advocate
Advocate

Pic 2 just shows the problem, that "create" uses the default shape bounding box.

I used "ElementTransformUtils" to move and rotate the stirrup, it works fine.

Thanks!

ParameterMap parametersMapDef = roundStirrupRebarShape.ParametersMap;
Parameter radiusParamDef = parametersMapDef.get_Item("R");
double defaultRadius = radiusParamDef.AsDouble();
double x = defaultRadius - 0.5 * stirrupDiameter;  //bug in revit!!! bounding box is not tnagent to the outter circle in x axis.  
double y = defaultRadius;

XYZ stirrCenter = org + x * xVect + y * yVect;
XYZ dOrg = colCenter - stirrCenter;
ElementTransformUtils.MoveElement(doc, roundStirrup.Id, dOrg);

 

0 Likes
Message 6 of 6

jeremy_tammik
Alumni
Alumni

So, the problem is solved now? Thank you for your confirmation!

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes