How to create Z-offset Extrusion via API

How to create Z-offset Extrusion via API

YaGitHub
Contributor Contributor
838 Views
3 Replies
Message 1 of 4

How to create Z-offset Extrusion via API

YaGitHub
Contributor
Contributor

Hi, kinds!

I wanna make a function for creating Extrusion easily like that:

Extrusion createExtrusionZ(CurveArrArray pProfile, double bottom, double height)
        {
            // mm to feet
            double bottomF = mmToFeet(bottom);
            double heightF = mmToFeet(height);

            // create Sketch Plane
            Plane pPlane = Plane.CreateByNormalAndOrigin(new XYZ(0.0,0.0,1.0),new XYZ(0.0,0.0,bottomF));
            SketchPlane pSketchPlane = SketchPlane.Create(_rvtDoc, pPlane) as SketchPlane;

            // return new Extrusion
            bool bIsSolid = true;
            return _rvtDoc.FamilyCreate.NewExtrusion(bIsSolid, pProfile, pSketchPlane, heightF);
        }

 

I expect that extrusion from [bottom] to [bottom + height] at Z direction, but I get that from [0] to [height] always.

I suspect that the way to create SketchPlane is mistaken, but I don't have any certain idea.

 

Could you give me a hand, gentles?

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

RPTHOMAS108
Mentor
Mentor
Accepted solution

Try putting your start Z values into the points in your profile.

Message 3 of 4

YaGitHub
Contributor
Contributor

Thank you, Sir.

I could understand the specification of NewExtrusion-function.

 

But I wanna make a function as I posted. Therefore I did like below:

 Extrusion createExtrusionZ(CurveArrArray pProfile, double bottom, double height)
        {
            // mmToFeet
            double bottomF = mmToFeet(bottom);
            double heightF = mmToFeet(height);

            // make sketch plane
            Plane pPlane = Plane.CreateByNormalAndOrigin(new XYZ(0.0,0.0,1.0),new XYZ(0.0,0.0,0.0));
            SketchPlane pSketchPlane = SketchPlane.Create(_rvtDoc, pPlane) as SketchPlane;

            // make Extrusion
            bool bIsSolid = true;
            Extrusion newExtrusion = _rvtDoc.FamilyCreate.NewExtrusion(bIsSolid, pProfile, pSketchPlane, heightF);

            // move Extrusion
            XYZ transPoint = new XYZ(0.0, 0.0, bottomF);
            ElementTransformUtils.MoveElement(_rvtDoc, newExtrusion.Id, transPoint);
            return newExtrusion;
        }

 

Step 1 : Make new Extrusion attached to Z=0

Step 2 : Move the Extrusion to expected Z

 

🧐

0 Likes
Message 4 of 4

RPTHOMAS108
Mentor
Mentor

Intuitively it would seem that the plane would set the z value as you had it but apparently not.

 

I don't know if there is a better option than moving the item after creation to enable you to have the same form of function. Curves in the profile can be iterated and transformed to new Z but I don't know if that would be advantageous or not.

0 Likes