Entity to Hatch

Started by technolog, February 01, 2007, 12:01:02 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

technolog

 Hello !

I want to change the properties of an Hatch entity with c++.

So, I have selected it with the Selection interface, then I have got the Entity interface with the Item fonction :

Doc->Selection()->SelectByID(EntityID, false);
EntityPtr Entity = Doc->Selection()->Item(1);

But I don't know how to convert the IDcadEntity received into a IDcadHatch.

I have tried to do a cast on the result of the EntityDataObject fonction, but it has produced an access violation error

I thank you by advance

technolog

Ho I'm sorry,

I work on C++ builder 6.0

Best regards

DrollTroll

#2
Okay, I think I begin to see your confusion.

IDcadHatch is only used to create new hatch entities. It is basically a mirror of the dialog box and options the user sees when he draws a new hatch pattern manually.

IDcadEntHatch is the interface that lets you interact with the points and properties of an existing entity via EntityDataObject.
To fully interact with an existing hatch entity, you need to cast the EntityDataObject to IDcadEntHatch.

Here are some code snippets from the makexyz sample project.


      //declarations
      EntityPtr DcEnt;
      EntHatchPtr EHatch;
      Designcad_tlb::DcEntityTypes eType;

      // make sure that EHatchPtr is not already occupied with another object's data
      EHatch.Unbind();

      // Assuming you have already obtained a valid DcEnt through other code
      DcEnt->EntityDataObject()->QueryInterface(IID_IDcadEntHatch, (void**)(&EHatch));
      if ((IDcadEntHatch*)EHatch == NULL) {
        sprintf(outBuff, "Null pointer on EHatch\n");
        OutFile->WriteBuffer(outBuff, strlen(outBuff));
        break;
      }
      double cSpan = EHatch->HatchAngle;
      double lScale = EHatch->HatchScale;
      int lType = EHatch->HatchType;



Sorry it all looks so convoluted. Working with COM objects in C++ is not as "pretty" as using VB or even Delphi.
25 years with DesignCAD

technolog

Ok, I understand now the signification of the access violations  ;)

Thank you very much DrollTroll


DrollTroll

25 years with DesignCAD