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

How to translate exsample at C++

4 REPLIES 4
Reply
Message 1 of 5
andreyka
448 Views, 4 Replies

How to translate exsample at C++

I need to add hatch into my drawing.
I have found exsample in documentation but I can not translate it at С++.
I get message “Invalid object array”.
Please say how to do it.

This is that exsample:

Sub Example_AddHatch()
' This example creates an associative hatch in model space.

Dim hatchObj As AcadHatch
Dim patternName As String
Dim PatternType As Long
Dim bAssociativity As Boolean

' Define the hatch
patternName = "ANSI31"
PatternType = 0
bAssociativity = True

' Create the associative Hatch object in model space

Set hatchObj = ThisDrawing.ModelSpace.AddHatch(PatternType, patternName, bAssociativity)

' Create the outer boundary for the hatch. (a circle)
Dim outerLoop(0 To 0) As AcadEntity
Dim center(0 To 2) As Double
Dim radius As Double
center(0) = 3: center(1) = 3: center(2) = 0
radius = 1
Set outerLoop(0) = ThisDrawing.ModelSpace.AddCircle(center, radius)


' Append the outerboundary to the hatch object, and display the hatch
hatchObj.AppendOuterLoop (outerLoop)
hatchObj.Evaluate
ThisDrawing.Regen True

End Sub
4 REPLIES 4
Message 2 of 5
Anonymous
in reply to: andreyka

Will you post your C++ translated code, and let's go from that?

Lewis
www.hlsolution.com

wrote in message news:5053454@discussion.autodesk.com...
I need to add hatch into my drawing.
I have found exsample in documentation but I can not translate it at ?++.
I get message "Invalid object array".
Please say how to do it.

This is that exsample:

Sub Example_AddHatch()
' This example creates an associative hatch in model space.

Dim hatchObj As AcadHatch
Dim patternName As String
Dim PatternType As Long
Dim bAssociativity As Boolean

' Define the hatch
patternName = "ANSI31"
PatternType = 0
bAssociativity = True

' Create the associative Hatch object in model space

Set hatchObj = ThisDrawing.ModelSpace.AddHatch(PatternType, patternName,
bAssociativity)

' Create the outer boundary for the hatch. (a circle)
Dim outerLoop(0 To 0) As AcadEntity
Dim center(0 To 2) As Double
Dim radius As Double
center(0) = 3: center(1) = 3: center(2) = 0
radius = 1
Set outerLoop(0) = ThisDrawing.ModelSpace.AddCircle(center, radius)


' Append the outerboundary to the hatch object, and display the hatch
hatchObj.AppendOuterLoop (outerLoop)
hatchObj.Evaluate
ThisDrawing.Regen True

End Sub
Message 3 of 5
andreyka
in reply to: andreyka

I use AutoCAD2000 and VC++ 6.0
it is my VC++ code:

IAcadApplication app;

app.CreateDispatch("AutoCAD.Application");
app.SetVisible(TRUE);

IAcadDocuments oDocs;
IAcadDocument oDoc;
IAcadModelSpace ModSp;

IAcadHatch Hatch;

COleVariant covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR),
covTrue((short)TRUE),
covFalse((short)FALSE);

oDocs = app.GetDocuments();
oDoc= oDocs.Add(covOptional);

ModSp = oDoc.GetModelSpace();

double center[]={100,100,0};

COleSafeArray saCenter;
saCenter.CreateOneDim(VT_R8,3,center);


IAcadCircle circle= ModSp.AddCircle(saCenter,50);

IAcadEntity *entity;
entity = new IAcadEntity;
*entity =(IAcadEntity)circle;

Hatch = ModSp.AddHatch(0,"ANSI31",TRUE);

LPDISPATCH lpDisp;

VARIANT var;
var.vt = VT_DISPATCH;

var.pdispVal = entity->m_lpDispatch;

Hatch.AppendOuterLoop(var);
Message 4 of 5
Anonymous
in reply to: andreyka

=========Beginning of the citation==============
COleSafeArray outerLoop;
outerLoop.CreateOneDim(VT_DISPATCH,1,&circle);
Hatch.AppendOuterLoop(outerLoop);
Hatch.Evaluate();
=========The end of the citation================


Best Regards,
Alexander Rivilis.
Message 5 of 5
andreyka
in reply to: andreyka

This is solution for a few lines which limit some area

void CTestACAD03Dlg::OnAcad()
{
IAcadApplication app;
app.CreateDispatch("AutoCAD.Application");
IAcadDocuments oDocs;
oDocs = app.GetDocuments();
IAcadDocument oDoc;
oDoc = oDocs.Add(COleVariant((short)FALSE));
IAcadModelSpace modsp;
modsp = oDoc.GetModelSpace();

double p11[]={100,100,0};
double p12[]={100,200,0};
double p21[]={100,200,0};
double p22[]={200,200,0};
double p31[]={200,200,0};
double p32[]={200,100,0};
double p41[]={200,100,0};
double p42[]={100,100,0};

COleSafeArray s11,s12,s21,s22,s31,s32,s41,s42;
s11.CreateOneDim(VT_R8,3,p11);
s12.CreateOneDim(VT_R8,3,p12);
s21.CreateOneDim(VT_R8,3,p21);
s22.CreateOneDim(VT_R8,3,p22);
s31.CreateOneDim(VT_R8,3,p31);
s32.CreateOneDim(VT_R8,3,p32);
s41.CreateOneDim(VT_R8,3,p41);
s42.CreateOneDim(VT_R8,3,p42);

IAcadLine ln1,ln2,ln3,ln4;

ln1 = modsp.AddLine(s11,s12);
ln2 = modsp.AddLine(s21,s22);
ln3 = modsp.AddLine(s31,s32);
ln4 = modsp.AddLine(s41,s42);

double centr[]={150,150,0};
COleSafeArray sacentr;
sacentr.CreateOneDim(VT_R8,3,centr);

IAcadCircle circle;
circle = modsp.AddCircle(sacentr,40);

/*
// для окружности - это единственный примитив

IAcadHatch hatch;
hatch = modsp.AddHatch(0,"ANSI31",TRUE);

COleSafeArray outerLoop;
outerLoop.CreateOneDim(VT_DISPATCH,1,&circle);

hatch.AppendOuterLoop(outerLoop);
hatch.Evaluate();
*/

// для нескольких примитивов

IAcadEntity *entity;

entity = new IAcadEntity[4];

entity[0] = (IAcadEntity)ln1;
entity[1] = (IAcadEntity)ln2;
entity[2] = (IAcadEntity)ln3;
entity[3] = (IAcadEntity)ln4;

IAcadHatch hatch2;
hatch2 = modsp.AddHatch(0,"ANSI31",TRUE);

COleSafeArray outerLoop2;
outerLoop2.CreateOneDim(VT_DISPATCH,4);

for(long i =0; i<4; i++) outerLoop2.PutElement(&i,entity);

hatch2.AppendOuterLoop(outerLoop2);
hatch2.Evaluate();

app.SetVisible(TRUE);
app.ZoomAll();
app.Quit();
}

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

Post to forums  

Autodesk Design & Make Report

”Boost