Curves Transform problem


(Karol Wierzbicki) #1

I have following code:

var transformMatrix = Transform.Translation(new Vector3d(0, 0, (V1 - V2) / A));

        foreach (var frame in listOfFrames)
        {
            foreach (var curve in frame)
            {
            curve.Transform(transformMatrix);
            }
        }

It works fine for translating Brep, but won’t work with curves, curves are not translated at all, what could be the problem? Is that because curves are inside List < List < Curve > > ? I will write that in a words, because there seem to be a problem with displaying List of list of curves in a post

Try to make a post with List < List < Curve > > without spaces between characters…

Edit:

It seems it works fine after all, my mistake…


(Rajaa Issa) #2

It should work with curves. Can you send a complete sample using GH or other platform to test it?
I put together a small sample using GHTransformCurves.gh (3.9 KB) in the attached. It works fine.


(Karol Wierzbicki) #3

Right now I have different problems with transform operations of points and curves. I can’t transform any point, and curves are transformed only for some number of first iterations of one of the loops, then transform operation fails, and new curves are created without transformation. I tried to create simple model of this activity, but can’t reproduce. I take under consideration, that this could be my mistake somewhere in the code, but still it’s quite strange.


(Steve Baer) #4

I think there might be a bug in your more complicated code. Transforming of Curves hasn’t come up as an issue before. Of course, I could be wrong and will gladly look into the issue if you can create a sample where the Transform doesn’t work.


(Karol Wierzbicki) #5

SO the problem is (probably), that I try to transform objects not with use of doc.Objects.Transform, but as follows:

GetObject go = new GetObject();
            go.SetCommandPrompt(“Select object”);
            go.GeometryFilter = ObjectType.Brep;
            go.Get();
            if (go.ObjectCount == 0)
                return Result.Failure;

ObjRef obj_ref = go.Object(0);

var transformVector = Transform.Translation(new Vector3d(0, 0, 1));

obj_ref.Brep().Transform(transformVector);
            boundingBox = obj_ref.Brep().GetBoundingBox(true);

doc.Objects.AddBrep(obj_ref.Brep());
            doc.Views.Redraw();

This way transformation will not work, is there a workaround for that? I just need to add to the Doc, final result of many transformations.


(Menno Deij - van Rijswijk) #6

You need to extract the Brep from the obj_ref first, then apply the transform(s), then add the transformed Brep to the document. Each call to obj_ref.Brep() will create a new Brep instance, so your transformed Brep gets lost.

ObjRef obj_ref = go.Object(0);
Brep b = obj_ref.Brep();

var transformVector = Transform.Translation(new Vector3d(0, 0, 1));
bool ok = b.Transform(transformVector);

if (ok) 
{
    doc.Objects.AddBrep(b);
    doc.Views.Redraw();
}


(Karol Wierzbicki) #7

OK, so I have actually simplified my example too much above, as I add my brep to the container in “real” example: container.Breps.Add(obj_ref.Brep()); and than do different operations on this brep in another part of code. But I have used bool to check if brep is translated or not (from example, that you have provided Menno), and it appeared, that it is translated.

I am trying to get bounding box for brep after translation, and each time I get exactly the same bounding box, what do I do wrong?

ObjRef obj_ref = go.Object(0);
            var list = new List < BoundingBox > ();
            for (int i = 0; i < 3; i++)
            {
                var transformVector = Transform.Translation(new Vector3d(0, 0, i));

var brep = obj_ref.Brep();
                brep.Transform(transformVector);
                var bb = brep.GetBoundingBox(true);
                list.Add(bb);
                doc.Objects.AddBrep(brep);
            }