C language > Work in progress

Pelles-C + OLE for access to AutoCAD

<< < (11/11)

sergey:
hr=8021007B

TimoVJL:
OK, only object array is accepted.
COMException (0x8021007B) "Incorrect array of objects"

This works with nanoCAD

--- Code: --- 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);
--- End code ---
or
--- Code: --- 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);

--- End code ---

sergey:
Code fragment:

--- Code: --- // 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);
}
--- End code ---

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: ---bstr = SysAllocString (L "ANSI31");
--- End code ---
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: ---while (scanf ( "%d %d %d", &p0, &p1, &p2)! = EOF)
--- End code ---
and to report at the end of the cycle of the number of processed triangles.

sergey:
Move the line:

--- Code: ---SafeArrayDestroy (psarrayL); // Free array
--- End code ---
to the end of the function and all healed.

--- Code: ---// 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
}
--- End code ---

sergey:
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.

Navigation

[0] Message Index

[*] Previous page

Go to full version