NO

Author Topic: Pelles-C + OLE for access to AutoCAD  (Read 5649 times)

Offline sergey

  • Member
  • *
  • Posts: 97
Re: Pelles-C + OLE for access to AutoCAD
« Reply #45 on: August 22, 2016, 10:44:39 pm »
Addition:

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 1640
Re: Pelles-C + OLE for access to AutoCAD
« Reply #46 on: August 23, 2016, 09:44:07 am »
Code: [Select]
Argument 'VARIANT HatchObjectType' not 'typedef enum acHatchObjectType'.
And if in AutoLISP or in VBA it's the optional argument (i.e., can be omitted), the C function without this argument does not work.
for your old code default value for unused parameter should be 0 in C
Code: [Select]
...
VARIANT HatchType;
HatchType.vt = VT_I4;
HatchType.lVal = 0;
...
May the source be with you

Offline sergey

  • Member
  • *
  • Posts: 97
Re: Pelles-C + OLE for access to AutoCAD
« Reply #47 on: August 23, 2016, 06:22:59 pm »
Hello, Timo!
I have thought that you have lost interest in the subject.

I've already tried Type VT_I4
Nevertheless, I repeat the experiment.
On the other hand experience with LISP code is also useful.

AutoCAD Hach for programming is difficult and in other CAD's.

This and previous project successfully compiled for AutoCAD 2012

Offline sergey

  • Member
  • *
  • Posts: 97
Re: Pelles-C + OLE for access to AutoCAD
« Reply #48 on: August 23, 2016, 07:57:13 pm »
Hatch objects are now created.
But the function
IAcadHatch_AppendOuterLoop(pHatch, vpnt);
is not executed.
Code: [Select]
// check 3dFace-mesh: if Surface is created - Hatch all 3dFaces to view Holes
void FindHoles (IAcadUtility* pUtility, IAcadModelSpace* pModelSpace, VARIANT* varpntlist)
{
//acHatch = 17;
VARIANT vHatchType;
//vHatchType.vt = VT_BOOL;
//vHatchType.boolVal = 0;
vHatchType.vt = VT_I4;
vHatchType.lVal = 0;

BSTR bstr = NULL;
VARIANT vpnt; // TypedArray for LWPolyLine
SAFEARRAY* psarrayL = SafeArrayCreateVector(VT_VARIANT, 0, 8);
long i = 0;
char sVal[48];
long p0, p1, p2;

pFile2 = stdin;
freopen("triangles.txt","r",stdin);  // reopen file as stdin for read

while (scanf("%d %d %d", &p0, &p1, &p2) !=EOF) {
// make LWPolyline from varpoints of 3dFace
((VARIANT*)psarrayL->pvData)[0].vt = VT_R8;
((VARIANT*)psarrayL->pvData)[0].dblVal = ((double*)varpntlist[p0].parray->pvData)[0];
((VARIANT*)psarrayL->pvData)[1].vt = VT_R8;
((VARIANT*)psarrayL->pvData)[1].dblVal = ((double*)varpntlist[p0].parray->pvData)[1];
((VARIANT*)psarrayL->pvData)[2].vt = VT_R8;
((VARIANT*)psarrayL->pvData)[2].dblVal = ((double*)varpntlist[p1].parray->pvData)[0];
((VARIANT*)psarrayL->pvData)[3].vt = VT_R8;
((VARIANT*)psarrayL->pvData)[3].dblVal = ((double*)varpntlist[p1].parray->pvData)[1];
((VARIANT*)psarrayL->pvData)[4].vt = VT_R8;
((VARIANT*)psarrayL->pvData)[4].dblVal = ((double*)varpntlist[p2].parray->pvData)[0];
((VARIANT*)psarrayL->pvData)[5].vt = VT_R8;
((VARIANT*)psarrayL->pvData)[5].dblVal = ((double*)varpntlist[p2].parray->pvData)[1];
((VARIANT*)psarrayL->pvData)[6].vt = VT_R8;
((VARIANT*)psarrayL->pvData)[6].dblVal = ((double*)varpntlist[p0].parray->pvData)[0];
((VARIANT*)psarrayL->pvData)[7].vt = VT_R8;
((VARIANT*)psarrayL->pvData)[7].dblVal = ((double*)varpntlist[p0].parray->pvData)[1];
// sarray for LWPoly inserted in vpnt
hr = IAcadUtility_CreateTypedArray(pUtility, &vpnt, VT_R8, psarrayL);
SafeArrayDestroy(psarrayL);  // free array
// draw LWPolyline in ModelSpace
if (!hr) {
hr = IAcadModelSpace_AddLightWeightPolyline(pModelSpace, vpnt, &pLWP);
IAcadLWPolyline_Update(pLWP);
}
// hr = IAcadModelSpace_AddHatch(pModelSpace, 1, L"SOLID", TRUE, HatchType, &pHatch);
bstr = SysAllocString(L"SOLID");
//bstr = SysAllocString(L"ANSI31");
hr = IAcadModelSpace_AddHatch(pModelSpace, 1, bstr, 1, vHatchType, &pHatch);
SysFreeString(bstr);
if (!hr) {
vpnt.vt = VT_DISPATCH;
vpnt.ppdispVal = (IDispatch **)pLWP;
hr = IAcadHatch_AppendOuterLoop(pHatch, vpnt); // OuterLoop = LWPolyline = 3dFace
if (hr) {
MessageBox(0, "hr error", "IAcadHatch_AppendOuterLoop", 0);
return;
}
hr = IAcadHatch_Evaluate(pHatch);
MessageBox(0, "Hatch added", "AddHatch", 0);
i++;
}
else MessageBox(0, "hr error", "IAcadModelSpace_AddHatch", 0);
VariantClear(&vpnt);
}
sprintf(sVal, "End of Hatch 3dFaces: %d triangles", i);
MessageBox(0, sVal, "FindHoles", 0);
freopen("CON","r", stdin);
}

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 1640
Re: Pelles-C + OLE for access to AutoCAD
« Reply #49 on: August 23, 2016, 10:12:33 pm »
What error code is?
« Last Edit: August 24, 2016, 07:16:49 pm by TimoVJL »
May the source be with you

Offline sergey

  • Member
  • *
  • Posts: 97
Re: Pelles-C + OLE for access to AutoCAD
« Reply #50 on: August 24, 2016, 03:48:53 pm »
hr=8021007B

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 1640
Re: Pelles-C + OLE for access to AutoCAD
« Reply #51 on: August 24, 2016, 06:47:34 pm »
OK, only object array is accepted.
COMException (0x8021007B) "Incorrect array of objects"

This works with nanoCAD
Code: [Select]
VARIANT voa; // object array
SAFEARRAYBOUND rgsaBound;
rgsaBound.lLbound = 0L; rgsaBound.cElements = 1;
voa.vt = VT_ARRAY | VT_DISPATCH;
voa.parray = SafeArrayCreate(VT_DISPATCH, 1, &rgsaBound);
long int i = 0;
hr = SafeArrayPutElement(voa.parray,&i,(void*)pLWPL);
hr = IAcadHatch_AppendOuterLoop(pHatch, voa);
or
Code: [Select]
VARIANT voa; // object array
SAFEARRAY* psarr = SafeArrayCreateVector(VT_DISPATCH, 0, 1);
IDispatch* parms[1];  // = {(IDispatch *)pLWPL};
parms[0] = (IDispatch *)pLWPL;
psarr->pvData = parms;
voa.vt = VT_ARRAY | VT_DISPATCH;
voa.parray = psarr;
hr = IAcadHatch_AppendOuterLoop(pHatch, voa);
« Last Edit: August 25, 2016, 01:50:47 pm by TimoVJL »
May the source be with you

Offline sergey

  • Member
  • *
  • Posts: 97
Re: Pelles-C + OLE for access to AutoCAD
« Reply #52 on: August 24, 2016, 08:00:49 pm »
Code fragment:
Code: [Select]
// draw LWPolyline in ModelSpace
if (!hr) {
hr = IAcadModelSpace_AddLightWeightPolyline(pModelSpace, vpnt, &pLWP);
IAcadLWPolyline_Update(pLWP);
}
//bstr = SysAllocString(L"SOLID");
bstr = SysAllocString(L"ANSI31");
hr = IAcadModelSpace_AddHatch(pModelSpace, 1, bstr, 1, vHatchType, &pHatch);
SysFreeString(bstr);
if (!hr) {
//new code start
VARIANT voa; // object array
SAFEARRAYBOUND rgsaBound;
rgsaBound.lLbound = 0L; rgsaBound.cElements = 1;
voa.vt = VT_ARRAY | VT_DISPATCH;
voa.parray = SafeArrayCreate(VT_DISPATCH, 1, &rgsaBound);
long int k = 0;
hr = SafeArrayPutElement(voa.parray,&k,(void*)pLWP);
hr = IAcadHatch_AppendOuterLoop(pHatch, voa);
//new code end
hr = IAcadHatch_Evaluate(pHatch);
VariantClear(&voa);
i++;
}
else {
sprintf(sVal, "hr=%x", hr);
MessageBox(0, sVal, "AddHatch", 0);
}
VariantClear(&vpnt);
}

Fixed, there is an improvement.

Code changes between:
// New code start
...
and:
// New code end

Lines of code "if (hr)" I removed after inspection - everything is fine.
Now Hatch performed, but only one time, then the program crashes.

I changed the type of Hatch on:
Code: [Select]
bstr = SysAllocString (L "ANSI31");Hatch type changes.

It is not clear where the program falls, she should go to the second line of the file with the points of indices:
Code: [Select]
while (scanf ( "%d %d %d", &p0, &p1, &p2)! = EOF)and to report at the end of the cycle of the number of processed triangles.
« Last Edit: August 24, 2016, 08:04:56 pm by sergey »

Offline sergey

  • Member
  • *
  • Posts: 97
Re: Pelles-C + OLE for access to AutoCAD
« Reply #53 on: August 24, 2016, 09:58:19 pm »
Move the line:
Code: [Select]
SafeArrayDestroy (psarrayL); // Free arrayto the end of the function and all healed.
Code: [Select]
// check 3dFace-mesh: if Surface is created - Hatch all 3dFaces to view Holes
void FindHoles (IAcadUtility* pUtility, IAcadModelSpace* pModelSpace, VARIANT* varpntlist)
{
//acHatch = 17;
VARIANT vHatchType;
vHatchType.vt = VT_I4;
vHatchType.lVal = 0;

BSTR bstr = NULL;
VARIANT vpnt; // TypedArray for LWPolyLine
SAFEARRAY* psarrayL = SafeArrayCreateVector(VT_VARIANT, 0, 8);
HRESULT hr;
long i = 0;
char sVal[48];
long p0, p1, p2;

pFile2 = stdin;
freopen("triangles.txt","r",stdin);  // reopen file as stdin for read
while (scanf("%d %d %d", &p0, &p1, &p2) !=EOF) {
// make LWPolyline from varpoints of 3dFace
((VARIANT*)psarrayL->pvData)[0].vt = VT_R8;
((VARIANT*)psarrayL->pvData)[0].dblVal = ((double*)varpntlist[p0].parray->pvData)[0];
((VARIANT*)psarrayL->pvData)[1].vt = VT_R8;
((VARIANT*)psarrayL->pvData)[1].dblVal = ((double*)varpntlist[p0].parray->pvData)[1];
((VARIANT*)psarrayL->pvData)[2].vt = VT_R8;
((VARIANT*)psarrayL->pvData)[2].dblVal = ((double*)varpntlist[p1].parray->pvData)[0];
((VARIANT*)psarrayL->pvData)[3].vt = VT_R8;
((VARIANT*)psarrayL->pvData)[3].dblVal = ((double*)varpntlist[p1].parray->pvData)[1];
((VARIANT*)psarrayL->pvData)[4].vt = VT_R8;
((VARIANT*)psarrayL->pvData)[4].dblVal = ((double*)varpntlist[p2].parray->pvData)[0];
((VARIANT*)psarrayL->pvData)[5].vt = VT_R8;
((VARIANT*)psarrayL->pvData)[5].dblVal = ((double*)varpntlist[p2].parray->pvData)[1];
((VARIANT*)psarrayL->pvData)[6].vt = VT_R8;
((VARIANT*)psarrayL->pvData)[6].dblVal = ((double*)varpntlist[p0].parray->pvData)[0];
((VARIANT*)psarrayL->pvData)[7].vt = VT_R8;
((VARIANT*)psarrayL->pvData)[7].dblVal = ((double*)varpntlist[p0].parray->pvData)[1];
// sarray for LWPoly inserted in vpnt
hr = IAcadUtility_CreateTypedArray(pUtility, &vpnt, VT_R8, psarrayL);
// draw LWPolyline in ModelSpace
if (!hr) {
hr = IAcadModelSpace_AddLightWeightPolyline(pModelSpace, vpnt, &pLWP);
IAcadLWPolyline_Update(pLWP);
}
//bstr = SysAllocString(L"SOLID");
bstr = SysAllocString(L"ANSI31");
hr = IAcadModelSpace_AddHatch(pModelSpace, 1, bstr, 1, vHatchType, &pHatch);
SysFreeString(bstr);
if (!hr) {
VARIANT voa; // object array
SAFEARRAYBOUND rgsaBound;
rgsaBound.lLbound = 0L; rgsaBound.cElements = 1;
voa.vt = VT_ARRAY | VT_DISPATCH;
voa.parray = SafeArrayCreate(VT_DISPATCH, 1, &rgsaBound);
long int k = 0;
hr = SafeArrayPutElement(voa.parray,&k,(void*)pLWP);
hr = IAcadHatch_AppendOuterLoop(pHatch, voa);
hr = IAcadHatch_Evaluate(pHatch);
VariantClear(&voa);
i++;
}
else {
sprintf(sVal, "hr=%x", hr);
MessageBox(0, sVal, "AddHatch", 0);
}
VariantClear(&vpnt);
}
SafeArrayDestroy(psarrayL);  // free array
sprintf(sVal, "End of Hatch 3dFaces: %d triangles", i);
MessageBox(0, sVal, "FindHoles", 0);
freopen("CON","r", stdin);
if(pFile2 != 0) fclose(pFile2);  // close file 2
}

Offline sergey

  • Member
  • *
  • Posts: 97
Re: Pelles-C + OLE for access to AutoCAD
« Reply #54 on: August 25, 2016, 05:19:16 pm »
I am very pleased to know that in a fabulously beautiful northern country living person, capable to spend their time and share their knowledge to help an unknown neighbor.

With TIMO and under his guidance, has turned yet another example of AutoCAD software Pelles-C.
The program code is far from perfect, but resolved such humble tasks as:
1. The construction of three-dimensional points on the surface in the form of irregular triangles (3dFaces),
2. 'Hatch' (brushing) triangles to see the missing islands (Holes),
3. The construction of triangles means AutoCAD-library acax[XX]enu.tlb and using LISP-program DTM.lsp,
4. brushing means triangles AutoCAD-library acax[XX]enu.tlb, or by means of LISP-commands,
5. Use for building points existing in the current AutoCAD drawing,
6. Use for the construction of points from a text file 'points.txt' (strings as: X Y Z).

The surface is constructed on the assumption that the set of points is 'Convex-Hull'
It certainly does not always correspond to the real data in the topography, hydrography and other applications.
But nothing and no one bothers to improve computing algorithms, which laid out in free access by Steve J. Fortune ((c) 1987-1992 years).

I would suggest to Mr. DMac place project 'acad_sirface' on one popular site, but remember that the headquarters of a large "SoftXxxx" company is located very close to him and abandoned the idea.

In this archive included project, which was compiled for AutoCAD 2010--2012
In the archive is FtypeLib.exe Converter - XXXX.TLB  --> XXXX.H (by author 'frankie' - an active member of this forum).
In the archive is also LISP-program 'DTM.lsp + DTM.dcl' by Romanian programmer Nicolae Manda.
« Last Edit: August 25, 2016, 05:27:33 pm by sergey »