Scaling a solid question

Scaling a solid question

denisyukJ
Advocate Advocate
447 Views
6 Replies
Message 1 of 7

Scaling a solid question

denisyukJ
Advocate
Advocate

Hi,

I have a Solid extracted from wall, now I want to scale 1.1 this solid from the mass center to use updated solid for ElementIntersectsSolidFilter.

Is this code correct cus filter doesn't give me results even when I set factor to 3.0 (much more then I needed)?

double scaleFactor = 1.1;
var pivot = solid.ComputeCentroid();
Transform scaleTransform = Transform.Identity;
scaleTransform.Origin = pivot;
scaleTransform.ScaleBasis(scaleFactor);
Solid scaledSolid = SolidUtils.CreateTransformed(solid, scaleTransform);

 

0 Likes
Accepted solutions (2)
448 Views
6 Replies
Replies (6)
Message 2 of 7

rcrdzmmrmnn
Advocate
Advocate

I think ScaleBasis returns "other" Transform, so you maybe wanna try something like this:

scaleTransform = scaleTransform.ScaleBasis(scaleFactor);


If it doesn't work you could create a DirectShape or even use DirectContext3D to be able to see the created solid and determine what is causing the issue

Message 3 of 7

Mohamed_Arshad
Advisor
Advisor
Accepted solution

Hi @denisyukJ 

 

As @rcrdzmmrmnn mentioned, the ScaleBasis Method returns the scaled transformation you need to replace the existing transform with. Since you're trying to scale the solid from the origin, Once I object is scaled it moves from the origin, we need to translate it to origin position using Transform.Origin. Refer to the code below for additional reference.

 

Scale without translate

  Transform transform = Transform.Identity;
  transform.Origin= extractedSolid.ComputeCentroid();
  transform = transform.ScaleBasis(2.0);

  Solid scaledSolid = SolidUtils.CreateTransformed(extractedSolid, transform);

Translation_1.gif

Scale and Translate it to origin

 ///Instead of Indentity Matrix take the BoundingBox of the Solid
 Transform transform = extractedSolid.GetBoundingBox().Transform;
 transform = transform.ScaleBasisAndOrigin(1.1);

 //After the Translation the Solid will be moved from the origin
 ///By using translation we can move the Solid to the origin
 transform.Origin = extractedSolid.ComputeCentroid() - transform.Origin;

  Solid scaledSolid = SolidUtils.CreateTransformed(extractedSolid, transform);

Translation_3.gif

Visualization Methods

List<GeometryObject> geoObjects = new List<GeometryObject>();
geoObjects.Add(scaledSolid);

using (Transaction createSolid = new Transaction(doc, "Visualize Solid"))
{
    createSolid.Start();

    DirectShape directShape = DirectShape.CreateElement(doc, new ElementId(BuiltInCategory.OST_GenericModel));
    directShape.SetShape(geoObjects);

    createSolid.Commit();
}

Hope this will helps 🙂


Mohamed Arshad K
Software Developer (CAD & BIM)

Message 4 of 7

denisyukJ
Advocate
Advocate

Thanks both of you @rcrdzmmrmnn@Mohamed_Arshad for great clarification, especially shape visualization method!

 

Message 5 of 7

denisyukJ
Advocate
Advocate

@Mohamed_Arshad 

Wait, strange behavior detected! Pivot point is floating depending of scale factor.

Here is sf=1.1 as I wanted.

hClqq5CgMz.gif

 

Here is sf=2.0 as you mentioned.

tDTkf3YaUu.gif

 

0 Likes
Message 6 of 7

Mohamed_Arshad
Advisor
Advisor
Accepted solution

Hi @denisyukJ 

 

I updated the above code snippet, Kindly check the above reply. Sorry slightly missed in my code. The actual problem was once you scale the object it will move from the location, you need to translate it to original position. Now you can try with any scale factor it will work.

Hope this will helps 🙂


Mohamed Arshad K
Software Developer (CAD & BIM)

Message 7 of 7

rcrdzmmrmnn
Advocate
Advocate

Glad you worked it out 😁

0 Likes