Tuesday, June 04, 2019

AU 2019 - Las Vegas

Voting is opened for AU2019 Las Vegas!
Please vote for my class:

"Modify files using Design Automation"

AutoCAD, Inventor, Revit and 3dsMax engines are now on the cloud and you can use them to perform batch operations, such as creating, modifying and migrating files or exporting data. This class will cover the basics on how to use app bundles, activities and workitems. Bring your own laptop or use the lab. This class requires basic knowledge on .NET and previous experience creating desktop apps for AutoCAD, Inventor, Revit or 3dsmax.

Key learnings:
• Understand the basics of Autodesk Forge
• Create your first app based on Autodesk Forge
• Learn how to define bundle and activity
• Learn how to use prepare files and submit workitem

Products:Forge, 3ds Max, Revit, AutoCADFocus:Getting started with new softwareTopics:AutoCAD and General Design, Software Development, Building Information Modeling (BIM)Industry:Software Development

Visit this page:

...and search for "Modify files using Design Automation"

Click "Vote" button to the left.

Thank you!

Tuesday, April 19, 2016

I’m going to be speaking at Forge DevCon 2016!

Autodesk has asked me to speak at their first-ever Forge Developers Conference (DevCon) to be held June 15-16 in San Francisco. DevCon is an immersive, high-level gathering of developers, innovators, and startups in the AEC, product design, and manufacturing space who are building next generation apps on the cloud.

If you are building a business leveraging the cloud, you really need to come to this conference!
DevCon is no ordinary conference – you’ll get hands-on with tools to help you create new service offerings, solutions and integrations for a cloud-connected product-development ecosystem; meet face-to-face with the largest community of developers in design and engineering from around the world; and learn best practices from industry experts and engineers utilizing and developing the Forge Platform.

If you’d like to join me at the conference, use this SPEAKER FRIENDS AND FAMILY CODE (SpkrFriendofcdesk) and receive 30% off of Early Bird & General Admission tickets.

For more information about the conference, check out the DevCon website.

Tuesday, August 18, 2015

Find all AcDbLine Intersections


This question came from Sandhya who asked how to find all line intersections into a drawing.
In this case, we will consider only intersections between AcDbLine entities.

First we need to prepare our CMap structure to be able to handle AcGePoint3d as the map key. The idea is to group all Lines passing through each intersection point.

CMap does not support AcGePoint3d because it does not know how to Hash it and also how to compare it as a key. To allow that we will need to define both HasKey and CompareElements templates as follows:

// These are template classes to allow AcGePoint3d do be used as a Key do CMap class
const double _dTol = 0.0001;

template<> UINT AFXAPI HashKey<AcGePoint3d> (AcGePoint3d key)
CString sPoint;
sPoint.Format(_T("%f,%f,%f"),key.x, key.y ,key.z);

UINT iHash = (NULL == &key) ? 0 : HashKey((LPCSTR)sPoint.GetBuffer());
return iHash;

template<> BOOL AFXAPI CompareElements<AcGePoint3d, AcGePoint3d> 
     (const AcGePoint3d* pElement1, const AcGePoint3d* pElement2)
if ((pElement1 == NULL) || (pElement2 == NULL))
return false;
AcGeTol gTol;
gTol.setEqualPoint(_dTol); // Point comparison tolerance
return (pElement1->isEqualTo(*pElement2,gTol));

Next, we will collect the AcDbLine entities in ModelSpace:

// Collect lines from ModelSpace
Acad::ErrorStatus es;
AcDbDatabase *pDb = acdbHostApplicationServices()->workingDatabase();
AcDbBlockTableRecordPointer pBTR(acdbSymUtil()->blockModelSpaceId(pDb),AcDb::kForWrite);

AcDbBlockTableRecordIterator *pIter = NULL;
pBTR->newIterator(pIter, true);
AcDbObjectIdArray arrLines;

AcDbEntity *pEnt = NULL;
es = pIter->getEntity(pEnt, AcDb::kForRead);
if (es == Acad::eOk)
if (pEnt->isKindOf(AcDbLine::desc()))


delete pIter;
pIter = NULL;

if (arrLines.length() == 0)
acutPrintf(_T("There are no lines in Model Space!\n"));
acutPrintf(_T("We've found %d lines in Model Space!\nChecking intersection with tolerance %f...\n"), 
arrLines.length(), _dTol);

Ok, with the lines collected we will then build our CMap with the information we need:

// Process lines in pairs
CMap<AcGePoint3d,AcGePoint3d,AcDbObjectIdArray,AcDbObjectIdArray&> mapLines;

for (int i=0; i<arrLines.length()-1; i++)
AcDbLine* pLineA = NULL;
if (acdbTransactionManager->getObject((AcDbObject*&)pLineA,arrLines[i], AcDb::kForRead) == Acad::eOk)
for (int j=i+1; j<arrLines.length(); j++)
AcDbLine* pLineB = NULL;
if (acdbTransactionManager->getObject((AcDbObject*&)pLineB,arrLines[j], AcDb::kForRead) == Acad::eOk)
AcGePoint3dArray arrPts;
if (pLineA->intersectWith(pLineB,AcDb::kOnBothOperands,arrPts) == Acad::eOk)
if (arrPts.length() > 0)
for (int p=0; p<arrPts.length(); p++)
AcDbObjectIdArray arrExist;
if (mapLines.Lookup(arrPts[p],arrExist) == TRUE)
// Existing point...
if (arrExist.contains(pLineA->objectId()) == false)

if (arrExist.contains(pLineB->objectId()) == false)
// New point...
AcDbObjectIdArray arrNewEnts;


To demonstrate the use of this information, we then use our CMap data to create AcDbPoint entities on ModeSpace and also print a small report at the command prompt:

// Just as demonstration, walk through points and add an AcDbPoint entity to ModelSpace then print the info
POSITION pos = mapLines.GetStartPosition();
while (pos)
AcGePoint3d ptKey(0,0,0);
AcDbObjectIdArray arrEnts;
mapLines.GetNextAssoc(pos,ptKey, arrEnts);

AcDbPoint* ptEnt = new AcDbPoint(ptKey);
AcDbObjectId idPointEnt;

CString sEnts;
for (int e=0; e<arrEnts.length(); e++)
ACHAR pBuff[255] = _T("");
CString sBuff;
sBuff.Format( (e==arrEnts.length()-1) ? _T("%s"): _T("%s,"), pBuff);
sEnts += sBuff;

CString sPromptReport;
sPromptReport.Format(_T("Point (%.4f, %.4f, %.4f) - Entities [%s]\n"),ptKey.x, ptKey.y, ptKey.z, sEnts);

This is the sample DWG (remember to adjust the PTYPE):

And this is the prompt result:

We've found 8 lines in Model Space!
Checking intersection with tolerance 0.000100...
Point (49.4194, 7.7097, 0.0000) - Entities [1E0,1E1]
Point (43.8908, 18.4889, 0.0000) - Entities [1DF,1E0]
Point (37.2051, 11.5104, 0.0000) - Entities [1DF,1E1]
Point (32.4059, 13.0038, 0.0000) - Entities [1DE,1E1]
Point (33.7651, 7.9199, 0.0000) - Entities [1DE,1DF]
Point (30.4900, 20.1703, 0.0000) - Entities [1DD,1DE]
Point (20.6648, 16.6573, 0.0000) - Entities [1E1,1E2]
Point (22.1562, 13.7469, 0.0000) - Entities [1DD,1E2]
Point (24.4172, 15.4897, 0.0000) - Entities [1DD,1E1]
Point (17.0892, 9.8415, 0.0000) - Entities [1DC,1DD]
Point (16.3380, 17.5581, 0.0000) - Entities [1DB,1DC]

Full source code can be downloaded from here:


Best regards!