Resetting Z Point coordinates

Resetting Z Point coordinates

k005
Advisor Advisor
1,051 Views
15 Replies
Message 1 of 16

Resetting Z Point coordinates

k005
Advisor
Advisor

Hello friends;


I want to set the Z values ​​of all objects in the drawing to 0. But I think there is an error somewhere in this code. It does not give 0 to Z values.

 

Thanks in advance to the helpful friend.

 

 

 

 private void btnMesleki_Click(object sender, EventArgs e)
        {
            this.Close();
                // Aktif belgeyi al
            Aapp.Document doc = aCap.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;

            // Kullanıcıdan nesneleri seçmesini iste
            PromptSelectionResult selRes = ed.GetSelection();
            if (selRes.Status != PromptStatus.OK)
            {
                ed.WriteMessage("Seçim iptal edildi veya hatalı.");
                return;
            }

            // Seçilen nesneleri al
            using (Transaction trans = db.TransactionManager.StartTransaction())
            using (Aapp.DocumentLock docLock = Adoc.LockDocument())
            {
                SelectionSet selSet = selRes.Value;
                foreach (ObjectId objId in selSet.GetObjectIds())
                {
                    Entity ent = trans.GetObject(objId, Adb.OpenMode.ForWrite) as Entity;

                    if (ent != null)
                    {
                        // Z koordinatını sıfırla
                        ent.TransformBy(Matrix3d.Displacement(new Vector3d(0, 0, -ent.GeometricExtents.MinPoint.Z)));
                    }
                }

                // İşlemleri tamamla
                trans.Commit();
            }

            // Ekrana yazı bas
            ed.WriteMessage("Seçilen nesnelerin Z koordinatları sıfırlandı.");
        }
    

 

0 Likes
1,052 Views
15 Replies
Replies (15)
Message 2 of 16

ActivistInvestor
Mentor
Mentor

See this post

0 Likes
Message 3 of 16

k005
Advisor
Advisor

How do we integrate it into the code I gave above?

0 Likes
Message 4 of 16

ActivistInvestor
Mentor
Mentor

It is an extension method. You just add it to your code file and then call it like it was a method of the Entity class.

 

 

<snip>
Entity ent = trans.GetObject(objId, Adb.OpenMode.ForWrite) as Entity;

if (ent != null)
{
   // Z koordinatini sifirla
   ent.TranslateToXYPlane();
}

<snip>

 

Message 5 of 16

k005
Advisor
Advisor

It's busy... I'll try. Thank you.

0 Likes
Message 6 of 16

k005
Advisor
Advisor

Cannot be accessed due to protection level. I'm getting the error.

 

2023-12-21_204944.png

0 Likes
Message 7 of 16

norman.yuan
Mentor
Mentor

AcRx means Autodesk.AutoCAD.Runtime

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 8 of 16

k005
Advisor
Advisor

Ok. Solution?

0 Likes
Message 9 of 16

kerry_w_brown
Advisor
Advisor

@k005 

 

The immediate solution is attached.
The long term solution is to study.

 

2023-12-22_07-48-23.png

2023-12-22_07-54-45.png


// Called Kerry or kdub in my other life.

Everything will work just as you expect it to, unless your expectations are incorrect. ~ kdub
Sometimes the question is more important than the answer. ~ kdub

NZST UTC+12 : class keyThumper<T> : Lazy<T>;      another  Swamper
Message 10 of 16

k005
Advisor
Advisor

Thank you. I didn't notice...


* Isn't there a much shorter ready-made code?

 

It will only give zero value to the Z points of 2D objects. will reset.

 

Thanks.

 

0 Likes
Message 11 of 16

kerry_w_brown
Advisor
Advisor

Perhaps have a look at this:

https://forums.autodesk.com/t5/net/setting-z-value-to-0-in-all-objects-in-a-drawing/m-p/11685654/hig...

 

added:

You really need to provide more information about your problems.

happy new year


// Called Kerry or kdub in my other life.

Everything will work just as you expect it to, unless your expectations are incorrect. ~ kdub
Sometimes the question is more important than the answer. ~ kdub

NZST UTC+12 : class keyThumper<T> : Lazy<T>;      another  Swamper
Message 12 of 16

ActivistInvestor
Mentor
Mentor

The code that I posted will only move objects so that the bottom of their bounding box is in the XY plane.

 

That makes the assumption that they are 2 dimensional objects that are parallel to the XY plane. If that's not the case then you need to be more specific about exactly what it is you are trying to do and what types of objects you are dealing with.

Message 13 of 16

k005
Advisor
Advisor

What I want to do is to set the Z point value of objects such as Line, polyline, circle, mline, Text, Mtext to zero. If it's already zero, it won't do anything.


for example a Line object. 500 units and at an angle of 14 degrees. Z1: 18 ,Z2: 35 change it to Z1: 0 , Z2: 0...

0 Likes
Message 14 of 16

k005
Advisor
Advisor

I added the class here. In the file I added below, it resets the Z value of only Circle objects. Other Line objects do not reset.

 

* I tried it in text and points. They also reset. OK.

 

 

0 Likes
Message 15 of 16

_gile
Consultant
Consultant

Hi,

For curves that aren't parallel to the XY plane, you can try the Curve.GetOrthoProjectedCurve method.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 16 of 16

k005
Advisor
Advisor

OK, let me investigate. Thank you.

0 Likes