Poll

Display center point

Display center point
0 (0%)
Display center point
1 (100%)

Total Members Voted: 1

Author Topic: Display center point  (Read 9249 times)

0 Members and 1 Guest are viewing this topic.

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6963
  • AKA Daniel
Re: Display center point
« Reply #15 on: December 17, 2009, 02:09:19 AM »
you need to iterate thought the selections set, here is a helper function to help

Code: [Select]
Acad::ErrorStatus SelectionSetToObjectIds( AcDbObjectIdArray &setIds, ads_name ssname )
{
  long sslength;
  ads_name ent;
  acedSSLength(ssname,&sslength);
  for (long i = 0; i < sslength; i++)
  {
    AcDbObjectId oId;
    acedSSName(ssname, i, ent);
    if(acdbGetObjectId(oId, ent) == eOk)
      setIds.append(oId);
    else
      return Acad::eNullObjectId;
  }
  return eOk;
}

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6963
  • AKA Daniel
Re: Display center point
« Reply #16 on: December 17, 2009, 02:15:42 AM »
As you know selection set can contain many objects, once you have converted the selection set to an AcDbObjectIdArray, you need to open each object in the array, cast it to a circle, if it's not null, print your values.

gnanapaul

  • Guest
Re: Display center point
« Reply #17 on: December 17, 2009, 02:34:10 AM »
Hi Daniel,

still its showing single circle center point.

I have added the function SelectionSetToObjectIds. How can i call this function?
from where i can call?


It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6963
  • AKA Daniel
Re: Display center point
« Reply #18 on: December 17, 2009, 02:50:00 AM »
something like

Code: [Select]
static void ExtTools_test(void)
  {
    OnShowPoints();
  }

  static Acad::ErrorStatus SelectionSetToObjectIds( AcDbObjectIdArray &setIds, ads_name ssname )
  {
    long sslength;
    ads_name ent;
    acedSSLength(ssname,&sslength);
    for (long i = 0; i < sslength; i++)
    {
      AcDbObjectId oId;
      acedSSName(ssname, i, ent);
      if(acdbGetObjectId(oId, ent) == eOk)
        setIds.append(oId);
      else
        return Acad::eNullObjectId;
    }
    return eOk;
  }


  static void OnShowPoints()
  {
    ads_name ss;
    if( RTNORM != acedSSGet(_T("P"),NULL,NULL,NULL,ss)) 
      return;

    AcDbObjectIdArray ids;
    if(SelectionSetToObjectIds(ids,ss) != Acad::eOk)
      return;

    for(size_t i = 0; i < ids.length() ; i++)
    {
      AcDbEntity* pObj = NULL;
      if(acdbOpenObject(pObj,ids[i],AcDb::kForRead) == Acad::eOk)
      {
        AcDbCircle* pCirc = AcDbCircle::cast(pObj);
        if (pCirc !=NULL)
        {
          double dRadius = pCirc->radius();
          AcGePoint3d ptCenter = pCirc->center();
          acutPrintf(_T("\ncenter (%g,%g,%g) radius %g"),
            ptCenter.x,ptCenter.y,ptCenter.z, dRadius);
        }
        pObj->close();
      }
      else
        acutPrintf(_T("\nFailed to open the object."));
    }
    acedSSFree(ss);
  }

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6963
  • AKA Daniel
Re: Display center point
« Reply #19 on: December 17, 2009, 02:55:25 AM »
you may need to remove the _T( ) or add tchar.h

gnanapaul

  • Guest
Re: Display center point
« Reply #20 on: December 17, 2009, 03:59:22 AM »
Hi Daniel,

this is also showing error.

Code: [Select]
void CSampDialog::OnShowPoints()
{
ads_name ss;
if( RTNORM != acedSSGet("P",NULL,NULL,NULL,ss))  
{
if( RTNORM != acedSSGet(NULL,NULL,NULL,NULL,ss))  
{
acDocManager->unlockDocument(acDocManager->curDocument());
return;
}
}

long nEnts;
acedSSLength(ss,&nEnts);
AcDbObjectIdArray entities(nEnts);
acutPrintf("\nFound %d Entities", nEnts);

double pRadius, y_value;
int rc;
ads_name en;
AcGePoint3d pt;

rc = acedEntSel("\nSelect circles: ", en, asDblArray(pt));
if (rc != RTNORM)
{
acutPrintf("\nNo entity selected...");
return;
}

AcDbObjectId eId, eId2;
acdbGetObjectId(eId, en);

AcDbObject *pDbObj;

AcDbCircle *pcircle;
AcGePoint3d *pCenter1 = new AcGePoint3d;
acdbOpenObject(pDbObj, eId, AcDb::kForRead);
AcDbCircle* pCircle = AcDbCircle::cast(pDbObj);
if(pCircle == NULL) // means the passed parameter is not an instance of AcDbCircle
return;
if(pCircle == NULL)
return;
AcGePoint3d pCenter = pCircle->center();
y_value = pCenter.y;
pRadius = pCircle->radius();
acutPrintf("Selected object Y value %f\n", y_value);
acutPrintf("Selected object X value %f\n", pCenter);

acedSSFree(ss);
}
This above code is working fine. and please tell me how to change the above code to show multiple(Selected)  circle's center point....

Really you are great. please help me...

Today is my dead line...

Thanks a lot....

gnanapaul

  • Guest
Re: Display center point
« Reply #21 on: December 17, 2009, 04:44:21 AM »
Hi Daniel,

Please help me...

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6963
  • AKA Daniel
Re: Display center point
« Reply #22 on: December 17, 2009, 05:26:34 AM »
I'm very sorry, your code is so seriously flawed that I recommend you toss what you have and start with the functions I showed you.


gnanapaul

  • Guest
Re: Display center point
« Reply #23 on: December 17, 2009, 05:37:10 AM »
I'm very sorry, your code is so seriously flawed that I recommend you toss what you have and start with the functions I showed you.



Hi Daniel,

I have used your functions only.

But it shows error.

The errors are

Code: [Select]
error C2065: 'SelectionSetToObjectIds' : undeclared identifier
warning C4018: '<' : signed/unsigned mismatch
error C2373: 'SelectionSetToObjectIds' : redefinition; different type modifiers
Error executing cl.exe.

please help me...

Thanks a lot...

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6963
  • AKA Daniel
Re: Display center point
« Reply #24 on: December 17, 2009, 05:40:27 AM »
did you add SelectionSetToObjectIds to your class? or your .h file?

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6963
  • AKA Daniel
Re: Display center point
« Reply #25 on: December 17, 2009, 05:48:01 AM »
if you want it as part of your class

Code: [Select]
//add this to your CSampDialog.h file
static Acad::ErrorStatus SelectionSetToObjectIds( AcDbObjectIdArray &setIds, ads_name ssname );

//add this to your CSampDialog.cpp
Acad::ErrorStatus CSampDialog::SelectionSetToObjectIds( AcDbObjectIdArray &setIds, ads_name ssname )
{
    long sslength;
    ads_name ent;
    acedSSLength(ssname,&sslength);
    for (long i = 0; i < sslength; i++)
    {
      AcDbObjectId oId;
      acedSSName(ssname, i, ent);
      if(acdbGetObjectId(oId, ent) == eOk)
        setIds.append(oId);
      else
        return Acad::eNullObjectId;
    }
    return eOk;
  }
« Last Edit: December 17, 2009, 05:56:45 AM by Daniel »

gnanapaul

  • Guest
Re: Display center point
« Reply #26 on: December 17, 2009, 05:49:13 AM »
did you add SelectionSetToObjectIds to your class? or your .h file?

yes. I have added like

Code: [Select]
SelectionSetToObjectIds( AcDbObjectIdArray &setIds, ads_name ssme );a also added
Code: [Select]
static void ExtTools_test(void);
static void OnShowPoints1() ;

gnanapaul

  • Guest
Re: Display center point
« Reply #27 on: December 17, 2009, 05:55:01 AM »
It is working good.

Really you are very very good person.

Thanks a lot....

 

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6963
  • AKA Daniel
Re: Display center point
« Reply #28 on: December 17, 2009, 05:59:10 AM »
You are welcome  :-)

gnanapaul

  • Guest
Re: Display center point
« Reply #29 on: December 17, 2009, 06:14:37 AM »
Hi Daniel,

I was run correcly at first time.

After that it is not running...

Code in CSampDialog.h

Code: [Select]
public:
CSampDialog( CWnd* pParent = NULL );

void OnCopy2Excell(const char* pWhat, const AcDbObject* pDbObj);
afx_msg void OnShowPoints();
static Acad::ErrorStatus SelectionSetToObjectIds( AcDbObjectIdArray &setIds, ads_name ssname );
static void ExtTools_test(void);

Code in CSampDialog.cpp
Code: [Select]
BEGIN_MESSAGE_MAP(CSampDialog, CDialog)
//{{AFX_MSG_MAP(CSampDialog)
ON_WM_CLOSE()
ON_MESSAGE(WM_ACAD_KEEPFOCUS, onAcadKeepFocus)
ON_BN_CLICKED(IDC_BUTTON2, OnShowPoints)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()


static void ExtTools_test(void)
 {
CSampDialog cmd;
cmd.OnShowPoints();
}

void CSampDialog::OnShowPoints()
{

ads_name ss;
    if( RTNORM != acedSSGet(_T("P"),NULL,NULL,NULL,ss)) 
    return;

AcDbObjectIdArray ids;
    if(CSampDialog::SelectionSetToObjectIds(ids,ss) != Acad::eOk)
    return;

for(size_t i = 0; i < ids.length() ; i++)
    {
AcDbEntity* pObj = NULL;
if(acdbOpenObject(pObj,ids[i],AcDb::kForRead) == Acad::eOk)
{
AcDbCircle* pCirc = AcDbCircle::cast(pObj);
if (pCirc !=NULL)
{
double dRadius = pCirc->radius();
AcGePoint3d ptCenter = pCirc->center();
acutPrintf(_T("\ncenter (%g,%g,%g) radius %g"),
ptCenter.x,ptCenter.y,ptCenter.z, dRadius);
}
pObj->close();
}
else
acutPrintf(_T("\nFailed to open the object."));
    }
acedSSFree(ss);
}

Acad::ErrorStatus CSampDialog::SelectionSetToObjectIds( AcDbObjectIdArray &setIds, ads_name ssname )
{
    long sslength;
    ads_name ent;
    acedSSLength(ssname,&sslength);
    for (long i = 0; i < sslength; i++)
    {
      AcDbObjectId oId;
      acedSSName(ssname, i, ent);
      if(acdbGetObjectId(oId, ent) == Acad::eOk)
        setIds.append(oId);
      else
        return Acad::eNullObjectId;
    }
    return Acad::eOk;
  }


what is the wrong with this?

Thanks...