How to scale a CurveLoop?

How to scale a CurveLoop?

rbarreiros.eng
Enthusiast Enthusiast
1,786 Views
7 Replies
Message 1 of 8

How to scale a CurveLoop?

rbarreiros.eng
Enthusiast
Enthusiast

Hi,

I'm trying to scale a CurveLoop. I got this curveloop from the CropRegionShapeManager that gets me the lines that define a view's cropbox.

I now would like to scale those 4 lines to create a smaller rectangle. I would think that I'd have to use the Transform method of the CurveLoop class and pass in a transform with an origin equal to the center point of the curves in the loop and a ScaleBasis applied to it.

    #Get the center point of the cropbox's BoundingBox
    bBox = view.CropBox
    bBoxModel = BoundingBoxXYZ()
    bBoxTransf = bBox.Transform
    bBoxModel.Min = bBoxTransf.OfPoint(bBox.Min)
    bBoxModel.Max = bBoxTransf.OfPoint(bBox.Max)
    bBoxcenter = XYZ((bBoxModel.Min.X+bBoxModel.Max.X)/2,(bBoxModel.Min.Y+bBoxModel.Max.Y)/2,(bBoxModel.Min.Z+bBoxModel.Max.Z)/2)
    
    #Project center point onto plane of the view
    plane = Plane.CreateByNormalAndOrigin(view.ViewDirection,view.Origin)
    v = bBoxcenter - plane.Origin
    dist = plane.Normal.DotProduct(v)
    cropRegionCenter = bBoxcenter - dist * plane.Normal

    #Cropbox Curve Loop
    cropboxCurveLoop = view.GetCropRegionShapeManager().GetCropShape()[0]
    #Create transform to scale the curve loop
    transf = Transform.Identity
    transf.Origin = cropRegionCenter
    transf = transf.ScaleBasis(0.9)
    cropboxCurveLoop.Transform(transf)

 

However, the created rectangle is in fact smaller, but not centered with the cropbox region. What am I missing?

0 Likes
Accepted solutions (1)
1,787 Views
7 Replies
Replies (7)
Message 2 of 8

Organon
Advisor
Advisor

@rbarreiros.eng,

 

Hi,

 

Try the ScaleBasisAndOrigin method.

https://www.revitapidocs.com/2021.1/460caa53-d288-7cfe-dbb8-eadf4682329d.htm

 

Regards,


Arquitectura | Análisis CAD & BIM | Diseño Paramétrico | Programación
BIM-METADATA | LinkedIn | YouTube
0 Likes
Message 3 of 8

rbarreiros.eng
Enthusiast
Enthusiast

Hi @Organon ,

Thanks for the suggestion. However, I had tried that and it's still not working. I figured that since I want the center of the transform to always be the same, regardless of the scale factor used, I should be using ScaleBasis instead of ScaleBasisAndOrigin which, as I understand, would also scale the origin accordingly.

Would I have to apply the transform to each curve within the CurveLoop, instead of the CurveLoop itself?

0 Likes
Message 4 of 8

RPTHOMAS108
Mentor
Mentor

If the thing is scaling correctly but off centre it likely indicates origin is wrong in transform being used. 

 

"Transform.ScaleBasisAndOrigin
The resulting transformation is equivalent to the application of this transformation and then the uniform scale, in this order.

Transform.ScaleBasis
The resulting transformation is equivalent to the application of the uniform scale and then this transformation, in this order."

 

Have you plotted the transform origin to see it is where you expect?

0 Likes
Message 5 of 8

rbarreiros.eng
Enthusiast
Enthusiast

Yes, that would make sense...However, I'm specifying the correct center point as you can see in the image. I'm reporting internal coordinates in Revit and I can confirm that is the result of the cropRegionCenter variable

rbarreiroseng_0-1625742923439.png

rbarreiroseng_1-1625743051098.png

However, the rectangle I get is off...

Please note that the rectangle I get when I use cropRegionCenter as the Origin of the Transform is even farther than the blue rectangle in the image. The image actually reports the rectangle with a Transform.Origin = XYZ(0,0,0).

Could it be that the Transform origin I have to use is somehow in relative coordinates instead of model coordinates?

 

0 Likes
Message 6 of 8

RPTHOMAS108
Mentor
Mentor

I'm unclear are you using Transform.Origin of 41.49, 12.34, 23.12 or 0,0,0?

 

Are you using ScaleBasis or ScaleBasisAndOrigin?

 

You should be scaling based on the centre point not 0,0,0. By comparing the X and Z values with direction of out of position it seems to be dragging it towards the model origin which indicates that is what you are scaling about.

0 Likes
Message 7 of 8

Organon
Advisor
Advisor
Accepted solution

@rbarreiros.eng,

 

You can apply multiple transformations to the curve loop:  move it to (0,0,0), scale it and move it back.

 

Transform t1 = Transform.CreateTranslation(XYZ.Zero.Subtract(cropRegionCenter));
Transform t2 = Transform.Identity.ScaleBasis(0.9);
            
cropboxCurveLoop.Transform(t1);
cropboxCurveLoop.Transform(t2);
cropboxCurveLoop.Transform(t1.Inverse);

 

Regards,


Arquitectura | Análisis CAD & BIM | Diseño Paramétrico | Programación
BIM-METADATA | LinkedIn | YouTube
0 Likes
Message 8 of 8

rbarreiros.eng
Enthusiast
Enthusiast

Many thanks @Organon ! That was it!