Editor.GetSelection and PromptSelectionOptions

Editor.GetSelection and PromptSelectionOptions

manohar2375
Advocate Advocate
14,833 Views
12 Replies
Message 1 of 13

Editor.GetSelection and PromptSelectionOptions

manohar2375
Advocate
Advocate

Hi,

Good morning.

 

 

I am using Editor.GetSelection method with PromptSelectionOptions object. Because i want to select only one object at each click on the dwg file then read the data of selected object. Below properties are assigned to PromptSelectionOptions object.

 

private PromptSelectionResult acSSPrompt = null;

 

PromptSelectionOptions psoOptions = new PromptSelectionOptions();
psoOptions.SingleOnly = true;
psoOptions.SinglePickInSpace = true;

 

acSSPrompt = m_acad_doc.Editor.GetSelection(psoOptions);

 

My requirement is each click(Selectiion) read data from selected object and stored in another array list for other process.

 

My problem is until 128 clicks(Selectiions) on dwg file getting data from acSSPrompt object and stored in another array list.
But after 128 clicks then getting below error from acSSPrompt object.


acSSPrompt.Status is Error
acSSPrompt.Value is null.

 

Could you please help me.

 

Thanks in Advance.

 

Regards,
Manohar.

0 Likes
Accepted solutions (1)
14,834 Views
12 Replies
Replies (12)
Message 2 of 13

manohar2375
Advocate
Advocate

Hi All,

 

Could you please help me anyone.

 

Thanks in Advance.

 

Regards,

Manohar.

0 Likes
Message 3 of 13

manohar2375
Advocate
Advocate
Hi All, Could you please help me anyone. Thanks in Advance. Regards, Manohar.
0 Likes
Message 4 of 13

kerry_w_brown
Mentor
Mentor

 

Perhaps you should post a complete sample to demonstrate your issue.

 

 


// 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
0 Likes
Message 5 of 13

nagamalliv
Enthusiast
Enthusiast

[CommandMethod("ClearPickFirst", CommandFlags.UsePickSet |

                CommandFlags.Redraw | CommandFlags.Modal)]

static public void ClearPickFirst()

{

    Document doc = Application.DocumentManager.MdiActiveDocument;

    Editor ed = doc.Editor;

 

    try

    {

        PromptSelectionResult result = ed.SelectImplied();

 

        if (result.Status != PromptStatus.OK)

            return;

 

        SelectionSet ss = result.Value;

        ObjectId[] ids = ss.GetObjectIds();

 

        ed.WriteMessage("Pick first has " +

                    ids.Length.ToString() + " entities");

 

        ObjectId[] newIds = new ObjectId[0];

 

        ed.SetImpliedSelection(newIds);

    }

    catch (System.Exception ex)

    {

        ed.WriteMessage(ex.Message);

    }

}

0 Likes
Message 6 of 13

kerry_w_brown
Mentor
Mentor

@nagamalliv wrote:

[CommandMethod("ClearPickFirst", CommandFlags.UsePickSet |

                CommandFlags.Redraw | CommandFlags.Modal)]

static public void ClearPickFirst()

{

    Document doc = Application.DocumentManager.MdiActiveDocument;

    Editor ed = doc.Editor;

 

    try

    {

        PromptSelectionResult result = ed.SelectImplied();

 

        if (result.Status != PromptStatus.OK)

            return;

 

        SelectionSet ss = result.Value;

        ObjectId[] ids = ss.GetObjectIds();

 

        ed.WriteMessage("Pick first has " +

                    ids.Length.ToString() + " entities");

 

        ObjectId[] newIds = new ObjectId[0];

 

        ed.SetImpliedSelection(newIds);

    }

    catch (System.Exception ex)

    {

        ed.WriteMessage(ex.Message);

    }

}


 

 

Hi Malli,

 

What does that code represent ??

The functionality appears to differ from the original posters problem.

 

Regards,

 

 


// 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
0 Likes
Message 7 of 13

manohar2375
Advocate
Advocate

Hi KerryBrown,

 

Thanks for your response.

 

Could you please see the below sample code:

 

public bool SelectBlock(string sStartNumber, bool bStartToRenumbering, out string err_msg)
{
bool bSelectBlock = true;
err_msg = "";
string sResult = "";
Database acCurDb = m_acad_doc.Database;
SelectionSet acSSet = null;
string sSelectedBlk_FixtureLocID_AttVal = "";
string sFixture_Code_Val = "";
PromptSelectionOptions psoOptions = new PromptSelectionOptions();
psoOptions.SingleOnly = true;
psoOptions.SinglePickInSpace = true;

//Clear Dictionary of Selected Block list
dicSelected_FixtureType_List.Clear();
acSSPrompt = null;
//This is the filter for blockreferences
//SelectionFilter Filter = new SelectionFilter(new TypedValue[] { new TypedValue(0, "INSERT") });
bool bStopBlkSelection = false;
Autodesk.AutoCAD.Internal.Utils.SetFocusToDwgView();
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
// Request for objects to be selected in the drawing area
acSSPrompt = m_acad_doc.Editor.GetSelection(psoOptions);

acSSet = acSSPrompt.Value;
if (acSSet != null)
{
iSelectionCount = iSelectionCount + 1;
int icount = acSSet.Count;
// If the prompt status is OK, objects were selected
if (acSSPrompt.Status == PromptStatus.OK)
{
acSSet = acSSPrompt.Value;
// Step through the objects in the selection set
int iSelCount = acSSet.Count;
string sNewFixtureCode = "";

foreach (SelectedObject acSSObj in acSSet)
{
// Check to make sure a valid SelectedObject object was returned
if (acSSObj != null)
{
DBObject objDB = acTrans.GetObject(acSSObj.ObjectId, OpenMode.ForRead);
if (objDB is BlockReference)
{
Entity acEnt = acTrans.GetObject(acSSObj.ObjectId, OpenMode.ForRead) as Entity;
BlockReference blkRef = acEnt as BlockReference;
long lBlkObjHandle = blkRef.Handle.Value;

ObjectId lBlkObjID = blkRef.Id;

bool bFixtureCodeFound = false;
string sFixtureTypeCode = "";
string sFixtureCodeMaxSequenceNo = "";
string sMaxFixtureLocID = "";
using (DocumentLock docLock = m_acad_doc.LockDocument())
{
if (clsFixtureXrecordeObj.IsThisBlockHasXrecord(objDB.Id))
{
bFixtureCodeFound = clsFixtureXrecordeObj.readSpecifiedXrecord(objDB.Id, clsPublicVariables.sFixture_Code, out sFixture_Code_Val, out inner_table);
if (bFixtureCodeFound == true)
{
if (sFixture_Code_Val != "")
{
bool sLoc_Att_Val = clsFixtureXrecordeObj.readSpecifiedXrecord(objDB.Id, clsPublicVariables.sFixture_Location_ID, out sSelectedBlk_FixtureLocID_AttVal, out inner_table);
//Checking Fixture Code and Location ID
if (sSelectedBlk_FixtureLocID_AttVal != "")
{
if(sSelectedBlk_FixtureLocID_AttVal.Substring(0,2) != sFixture_Code_Val.Substring(2,2))
{
sSelectedBlk_FixtureLocID_AttVal = sFixture_Code_Val.Substring(2, 2) + sSelectedBlk_FixtureLocID_AttVal.Substring(2, 3);
}
}
if (sSelectedBlk_FixtureLocID_AttVal.Trim() == "")
{
//getting Fixture type from Fixture Code.
sNewFixtureCode = sFixture_Code_Val.Substring(2, 2);
bool bGenerate_update = Generate_Update_Loc_ID(sNewFixtureCode, sStartNumber, blkRef, lBlkObjID, bStartToRenumbering, sSelectedBlk_FixtureLocID_AttVal, out err_msg);
if (bGenerate_update == false)
{
bSelectBlock = false;
break;
}
}
else
{
if (bStartToRenumbering == true && sStartNumber != "")
{
//Getting Fixture Type Code
sNewFixtureCode = sFixture_Code_Val.Substring(2, 2);
bool bChkBoxStatus = false;
bool bStatus = false;
if (clsPublicVariables.bCheckBoxbChkBoxOverWriteScreen == false)
{
//displaying overwrite screen.
bStatus = DisplayLocIDOverWriteScreen(ref bChkBoxStatus, sNewFixtureCode);
}
else
{
//Wantendly setting 'TRUE' because already checked 'CHECKBOX' and selected 'YES' button on overwrite screen.
bStatus = true;
}
//Checking the 'YES' and 'NO' options on LOC id Over write screen
if (bStatus == true)
{
bSelectBlock = Generate_Update_Loc_ID(sNewFixtureCode, sStartNumber, blkRef, lBlkObjID, bStartToRenumbering, sSelectedBlk_FixtureLocID_AttVal, out err_msg);
if (bSelectBlock == false)
{
bSelectBlock = false;
break;
}

}
else
{
//Display Attributes on Renumbering screen
ShowAttributesOnUserForm("", "", "", "", "");
}
}
else
{
//Getting Max Sequence number from Dictionary.
sFixtureTypeCode = sSelectedBlk_FixtureLocID_AttVal.Substring(0, 2);
sFixtureCodeMaxSequenceNo = dicExist_Fixture_Types[sFixtureTypeCode];
sMaxFixtureLocID = sFixtureTypeCode + sFixtureCodeMaxSequenceNo;
string sErr_msg = "Location ID to the Fixture is already assigned" + Environment.NewLine + " To change the Location ID explicitly, Please use the Start renumbering option.";
//Display Attributes on Renumbering screen
ShowAttributesOnUserForm("", sSelectedBlk_FixtureLocID_AttVal, "", sErr_msg, sMaxFixtureLocID);
clsMessage.ShowInformationMessage(sErr_msg);
ShowAttributesOnUserForm("", "", "", "", "");
bFixtureCodeFound = true;
}
}

}
else
{
sResult = "Not Assigned : Not an IFP Block.";
//Display Attributes on Renumbering screen
ShowAttributesOnUserForm("", "", "", sResult, "");
}
}
}
else
{
sResult = "Not Assigned : Not an IFP Block.";
//Display Attributes on Renumbering screen
ShowAttributesOnUserForm("", "", "", sResult, "");
}
}
}
}
}
}
}
else
{

}
//checking the Mouse selection on floor plan wheather Error(Right Click) or Not
if (acSSPrompt.Status == PromptStatus.Cancel)
{
bStopBlkSelection = true;
//Display Attributes on Renumbering screen
ShowAttributesOnUserForm("", "", "", "","");
}
acTrans.Commit();
acSSPrompt = null;

}
//Checking the Mouse selection on floor plan
if (bStopBlkSelection == false)
{
//Calling again
if (bSelectBlock == true)
{
bSelectBlock = SelectBlock(sStartNumber, bStartToRenumbering, out err_msg);
if (bSelectBlock == false)
{
bSelectBlock = false;
}
}
}
return bSelectBlock;
}

 

Thanks in Advance.

 

Regards,

Manohar.

0 Likes
Message 8 of 13

manohar2375
Advocate
Advocate

Hi Kerry Brown,

 

I am extremely sorry for the previous whole code, could you please see the below sample code which is having problem to me. After 127 clicks(selections) is not selecting the object, getting the error.

 

public bool SelectBlock_new1()
{
bool bSelectBlock = true;
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database acCurDb = doc.Database;
SelectionSet acSSet = null;
PromptSelectionOptions psoOptions = new PromptSelectionOptions();
psoOptions.SingleOnly = true;
psoOptions.SinglePickInSpace = true;

acSSPrompt = null;
//bool bStopBlkSelection = false;
Autodesk.AutoCAD.Internal.Utils.SetFocusToDwgView();
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
acSSPrompt = doc.Editor.GetSelection(psoOptions);
acSSet = acSSPrompt.Value;
if (acSSet != null)
{
bSelectBlock = true;
}
else
{
bSelectBlock = false;
}
if (bSelectBlock == true)
{
bSelectBlock = SelectBlock_new1();
}
}
return true;
}

 

Thanks in Advance.

 

Regards,

Manohar.

0 Likes
Message 9 of 13

nagamalliv
Enthusiast
Enthusiast

Hi Manohar,

 

AutoCAD having a maximum selection sets value, please dispose your selection set by using keyword for selection set. for example use below sample.

 

var selResult = doc.Editor.GetSelection();

                        using (var selSet = selResult.Value)
                        {
                            /// your code...
                        }

0 Likes
Message 10 of 13

_gile
Consultant
Consultant
Accepted solution

Hi,

 

It seems to me the number of active selections is not limited with .NET as it is with COM or AutoLISP (128), but may be the number of nested transaction is limited.

 

Anyway, the following code seems to work.

 

        public void SelectionTest()
        {
            var ed = AcAp.DocumentManager.MdiActiveDocument.Editor;
            var pso = new PromptSelectionOptions();
            pso.SingleOnly = true;
            pso.SinglePickInSpace = true;
            PromptSelectionResult psr;
            var ids = new ObjectIdCollection();
            while (true)
            {
                psr = ed.GetSelection(pso);
                if (psr.Status != PromptStatus.OK)
                    break;
                ids.Add(psr.Value[0].ObjectId);
                ed.WriteMessage("\n{0} selected objects", ids.Count);
            }
        }


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 11 of 13

manohar2375
Advocate
Advocate

Hi Malli,

 

Thanks for your code, Now my issue has solved by using your code.

 

Hi Gilles,

 

Thanks for your response and your valuable time and code.

 

Regards,

Manohar.

0 Likes
Message 12 of 13

BKSpurgeon
Collaborator
Collaborator
0 Likes
Message 13 of 13

_gile
Consultant
Consultant

@BKSpurgeon  a écrit :
Would the ObjectIdCollection need to be disposed?

No, The ObjectId structure does not implement IDisposable (i.e. does not have a Dispose() method).



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes