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

AcDbHatch in 3d

23 REPLIES 23
SOLVED
Reply
Message 1 of 24
PEPANOVAK
1885 Views, 23 Replies

AcDbHatch in 3d

I can in 2d, but in 3d not working (after setting ECS by 3dface)...

 

Any idea?

 

Thanks.

 

Pepa

23 REPLIES 23
Message 2 of 24
owenwengerd
in reply to: PEPANOVAK

Please don't use the phrase "not working" in a technical forum, as it is not helpful to those wanting to assist you. Best to show your code, describe what you did and the context you did it in, what you expected to happen, and what actually happened.

--
Owen Wengerd
ManuSoft
Message 3 of 24
PEPANOVAK
in reply to: owenwengerd

Owen, I have a 3D triangular network (TIN) and I need to hatch the individual triangles in 3D. I'm trying to use acdbhatch, but I'm doing it only in 2D.

The idea was to set the ECS by the triangle and then transform hatch.originPoint () to the ECS, but originPoint () returns zero coordinates...

Message 4 of 24
nick83
in reply to: PEPANOVAK

if you use SOLID hatch, try to use AcDbSolid.
IMHO AcDbHatch is for 2D space. in 3D it gives only a headache.
ps: in 3d you have to set ucs by view to see your hatch in current coord system
Message 5 of 24
PEPANOVAK
in reply to: nick83

It is strange that the editor 3d hatch manually creates (ECS set up by the object, run the command HATCH a show point inside)...

 


I would use acdbhatch due to the gradient. The lowest point of the network to differentiate from the highest.

Message 6 of 24
owenwengerd
in reply to: PEPANOVAK


@PEPANOVAK wrote:

Owen, I have a 3D triangular network (TIN) and I need to hatch the individual triangles in 3D. I'm trying to use acdbhatch, but I'm doing it only in 2D.

The idea was to set the ECS by the triangle and then transform hatch.originPoint () to the ECS, but originPoint () returns zero coordinates...


It's difficult to guess what the problem is without seeing your code.

--
Owen Wengerd
ManuSoft
Message 7 of 24
PEPANOVAK
in reply to: owenwengerd

AcDbMpolygon also not drawn correctly in 3D...

// A,B,C is AcGePoint3d

                    for (Adesk::UInt32 i=0; i < numFaces; i++) {
                        trig=sezT[i];
                        A=trig.pointA;
                        B=trig.pointB;
                        C=trig.pointC;
                        Z1=min(min(A.z,B.z),min(B.z,C.z));
                        //Z3=max(max(A.z,B.z),max(B.z,C.z));
                        krok=(int) Z1 / elev;
                        AcGePlane plane(A,B,C);
                      //  normal=plane.normal();
                      //  normal.normalize();

                      //  AcGeVector3d normalX(0,0,1);

                        AcDbMPolygon *pPol = new AcDbMPolygon();
                        AcGePoint2dArray parr;
                        AcGeDoubleArray bulges;

                        bulges.append(0.0);
                        bulges.append(0.0);
                        bulges.append(0.0);
                        bulges.append(0.0);

                        setECSasUCS(plane);

                        bod[0]=A.x; bod[1]=A.y; bod[2]=A.z;
                        acedTrans(bod,&fromrb,&torb,0,bodtrans);
                        A2.x=bodtrans[0];
                        A2.y=bodtrans[1];

                        bod[0]=B.x; bod[1]=B.y; bod[2]=B.z;
                        acedTrans(bod,&fromrb,&torb,0,bodtrans);
                        B2.x=bodtrans[0];
                        B2.y=bodtrans[1];

                        bod[0]=C.x; bod[1]=C.y; bod[2]=C.z;
                        acedTrans(bod,&fromrb,&torb,0,bodtrans);
                        C2.x=bodtrans[0];
                        C2.y=bodtrans[1];

                        parr.append(A2);
                        parr.append(B2);
                        parr.append(C2);
                        parr.append(A2);


                        pPol->appendMPolygonLoop(parr,bulges,FALSE);
                        //pPol->setNormal(normal);
                        pPol->setPattern(AcDbHatch::kPreDefined, _T("SOLID"));
                        pPol->evaluateHatch();
                        addToModelSpace(eId,pPol);

                    }

Message 8 of 24
owenwengerd
in reply to: PEPANOVAK

You will need to call setNormal() and setElevation() at minimum, and those are best set *before* adding vertices. It's difficult to determine just from looking at the code, but I think there are flaws in your math. Also, I'm not sure what setECSasUCS(plane) is for.

--
Owen Wengerd
ManuSoft
Message 9 of 24
PEPANOVAK
in reply to: owenwengerd

Owen: If I set the setNormal()  of values of triangle plane, so my hatch draw completely outside...If I set the setNormal(0,0,1), so my hatch draw in 2d...

Message 10 of 24
PEPANOVAK
in reply to: PEPANOVAK

Here is code...

                    for (Adesk::UInt32 i=0; i < numFaces; i++) {
                        trig=sezT[i];
                        A=trig.pointA;
                        B=trig.pointB;
                        C=trig.pointC;
                        AcGePlane plane(A,B,C);
                        normal=plane.normal();
                        //normal.normalize();

                        AcGeVector3d normalX(0,0,1);

                        AcDbMPolygon *pPol = new AcDbMPolygon();
                        AcGePoint2dArray parr;
                        AcGeDoubleArray bulges;

                        bulges.append(0.0);
                        bulges.append(0.0);
                        bulges.append(0.0);
                        bulges.append(0.0);

                        //AcGeMatrix3d mat=SetECSasUCS(plane);


                        parr.append(AcGePoint2d(A.x,A.y));
                        parr.append(AcGePoint2d(B.x,B.y));
                        parr.append(AcGePoint2d(C.x,C.y));
                        parr.append(AcGePoint2d(A.x,A.y));

                        pPol->setNormal(normal);
                        pPol->setElevation(0.0);

                        pPol->appendMPolygonLoop(parr,bulges,FALSE);
                        pPol->setPattern(AcDbHatch::kPreDefined, _T("SOLID"));
                        pPol->evaluateHatch();
                        addToModelSpace(eId,pPol);
                    }

Message 11 of 24
owenwengerd
in reply to: PEPANOVAK

Here is code that works correctly for AcDbHatch in AutoCAD 2010 and AutoCAD 2015. When I tested in AutoCAD 2010, AcDbMPolygon returned an incorrect matrix from getEcs(). AcDbMPolygon::getEcs() works correctly in AutoCAD 2015, so apparently the bug has since been fixed.

 

AcGePoint3d ptA(3,4,5);
AcGePoint3d ptB(4,5,6);
AcGePoint3d ptC(2,2,2);

AcGePlane planeTarget(ptA, ptB, ptC);
AcGeVector3d vecNormal = planeTarget.normal();
double dElevation = AcGePoint3d::kOrigin.distanceTo(AcGePoint3d::kOrigin.orthoProject(planeTarget));

AcDbHatch* pHatch = new AcDbHatch();
Acad::ErrorStatus es = pHatch->setElevation(dElevation); assert(es==Acad::eOk);
es = pHatch->setNormal(vecNormal); assert(es==Acad::eOk);

AcGeMatrix3d mxECS;
pHatch->getEcs(mxECS);
mxECS.invert();

AcGePoint2d pt2A = ptA.transformBy(mxECS).convert2d(AcGePlane::kXYPlane);
AcGePoint2d pt2B = ptB.transformBy(mxECS).convert2d(AcGePlane::kXYPlane);
AcGePoint2d pt2C = ptC.transformBy(mxECS).convert2d(AcGePlane::kXYPlane);

AcGePoint2dArray rpt2Loop;
rpt2Loop.append(pt2A);
rpt2Loop.append(pt2B);
rpt2Loop.append(pt2C);
rpt2Loop.append(pt2A);

es = pHatch->appendLoop(AcDbHatch::kExternal, rpt2Loop, AcGeDoubleArray()); assert(es==Acad::eOk);
es = pHatch->setPattern(AcDbHatch::kPreDefined, ACRX_T("SOLID")); assert(es==Acad::eOk);
es = pHatch->evaluateHatch(); assert(es==Acad::eOk);

AcDbBlockTableRecord* pSpace = NULL;
if (Acad::eOk == acdbOpenObject(pSpace, acdbCurDwg()->currentSpaceId(), AcDb::kForWrite))
{
	es = pSpace->appendAcDbEntity(pHatch); assert(es==Acad::eOk);
	pSpace->close();
	pHatch->close();
}
else
	delete pHatch;

 

--
Owen Wengerd
ManuSoft
Message 12 of 24
PEPANOVAK
in reply to: owenwengerd

Thank You Very Much Owen !

 

Pepa

Message 13 of 24
PEPANOVAK
in reply to: PEPANOVAK

I ran into a problem with some triangles (like this one). Draw somewhere outside.   

        -56.36       44.44    87.11    
        -74.20       33.40    86.03    
        -56.34       22.83   101.75    

All triangles is CCW...

 

Do you have any idea Owen?

 

Thanks.

Pepa

Message 14 of 24
owenwengerd
in reply to: PEPANOVAK

What exactly is the problem? Error status returned? Wrong location?

--
Owen Wengerd
ManuSoft
Message 15 of 24
PEPANOVAK
in reply to: owenwengerd

Wrong location. Picture is attached...

 

I've found that it depends on the order of vertex of a triangle, but I could not find the logic.

 

Thanks.

Message 16 of 24
PEPANOVAK
in reply to: owenwengerd

In the pictures are triangles with vertices CW and CCW...

Message 17 of 24
owenwengerd
in reply to: PEPANOVAK

Sorry, but I'm not going to debug your code for you. Show us some test code that demonstrates where and how it is failing with CW and CCW triangles. I'd start with the normal vector.

--
Owen Wengerd
ManuSoft
Message 18 of 24
PEPANOVAK
in reply to: owenwengerd

OK, I'm sorry...

 

Pepa

 

Message 19 of 24
PEPANOVAK
in reply to: owenwengerd

So I found a mistake 🙂

 

double dElevation = AcGePoint3d::kOrigin.distanceTo(AcGePoint3d::kOrigin.orthoProject(planeTarget)); 

 

It is wrong, only returns a positive value.

 

I wrote a custom function to calculate the distance from the plane and already it works...

Message 20 of 24
owenwengerd
in reply to: PEPANOVAK

Ah, good work and good catch.
--
Owen Wengerd
ManuSoft

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

Post to forums  

Autodesk Design & Make Report

”Boost