.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How get position of selected Entity?

5 REPLIES 5
Reply
Message 1 of 6
Jonarhipov
3988 Views, 5 Replies

How get position of selected Entity?

Hello everyone! I try to get position of the selected entity. But acEnt is not containts such methods or properties. What i do wrong?

Thanks!

 

My C# code:

//C#

[CommandMethod("GetCurCoords", CommandFlags.UsePickSet)]
        public void GetCurCoords()
        {
            Editor acEditor = Application.DocumentManager.MdiActiveDocument.Editor;
            PromptSelectionResult acPSR = acEditor.GetSelection();

            Document acDoc = Application.DocumentManager.MdiActiveDocument;
            Transaction acTrans = acDoc.TransactionManager.StartTransaction();
            using (acTrans)
            {
               if (acPSR.Value.Count == 1 && acPSR.Status==PromptStatus.OK)
               {
                   SelectionSet acSSet = acPSR.Value;
                   foreach (SelectedObject acSObj in acSSet)
                   {
                       if (acSObj != null)
                       {
                           Entity acEnt = acTrans.GetObject(acSObj.ObjectId,
                               OpenMode.ForRead) as Entity;
                           if (acEnt != null)
                           {
                               acEnt.// I'm trying to get position
                           }
                       }
                   }
                   acTrans.Commit();
               }
            }
        }

 

5 REPLIES 5
Message 2 of 6
hgasty1001
in reply to: Jonarhipov

Hi,

 

An entity it's a very generic object that can or not have a position propertie, you better try to narrow your selection to specific entities that have a position propertie (DBtext, block references, etc), lines for example doesn't have "a position", just a start and end point. Please try to explain in more datail what is your aim.

 

Gaston Nunez

Message 3 of 6
Jonarhipov
in reply to: hgasty1001

Thanks for answer. Drawing containts some Circles (as though Houses). My aim is get a position of one of the selected Circle (house). Each object i will bind with Array (Operator, Management company, ect).
I'm in the stage of getting coordinates of circle (house).
Sorry for the grammar mistakes.

Arhipov Evjeniy
Message 4 of 6
hgasty1001
in reply to: Jonarhipov

Hi,

 

Try this, not tested:

 

public Point3dCollection GetCircleCenters()
{
	Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
	Database db = HostApplicationServices.WorkingDatabase();
	SelectionSet acSSet = default(SelectionSet);
	Point3dCollection ret = new Point3dCollection();

	using (Transaction acTrans = db.TransactionManager.StartTransaction()) {
		TypedValue[] acTypValAr = new TypedValue[1];

		acTypValAr.SetValue(new TypedValue(DxfCode.Start, "CIRCLE"), 0);

		SelectionFilter acSelFtr = new SelectionFilter(acTypValAr);
		PromptSelectionResult acSSPrompt = default(PromptSelectionResult);

		acSSPrompt = ed.SelectAll(acSelFtr);
		if (acSSPrompt.Status == PromptStatus.OK) {
			acSSet = acSSPrompt.Value;
			int n = acSSet.Count - 1;
			int i = 0;

			for (i = 0; i <= n; i++) {
				Circle circ = acSSet(i).ObjectId.GetObject(OpenMode.ForRead);
				ret.Add(circ.Center);
			}
		}
	}

	return ret;
}

 

Gaston Nunez

Message 5 of 6
cdinten
in reply to: Jonarhipov

i do not know what you exactly want to do,if just the location of an entity, how about using the Entity.GeometricExtents property?
Message 6 of 6
Jonarhipov
in reply to: cdinten

gasty1001, cdinten, Thanks a lot!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost