Get intersections with BoundingBoxIntersectWith

Hi, I’m trying to find the intersections my labels might have with another object. And for that I’m using the BoundingBoxIntersectWith() method, but I’m getting the following error: eInvalidExtents and I don’t understand what’s wrong and how to solve it.

Entity.BoundingBoxIntersectWith(Entity, Autodesk.AutoCAD.DatabaseServices.Intersect, Point3dCollection, IntPtr, IntPtr) Method

Here is my python script:

# Load the Python Standard and DesignScript Libraries
import sys #sys is a fundamental Python library - here, we're using it to load in the standard IronPython libraries
import clr #This is .NET's Common Language Runtime. It's an execution environment that is able to execute code from several different languages.

# Add Assemblies for AutoCAD and Civil3D
clr.AddReference('AcMgd')
clr.AddReference('AcCoreMgd')
clr.AddReference('AcDbMgd')
clr.AddReference('AecBaseMgd')
clr.AddReference('AecPropDataMgd')
clr.AddReference('AeccDbMgd')
clr.AddReference('ProtoGeometry') #A Dynamo library for its proxy geometry
#classes. You'll only need this if you're interacting with geometry
clr.AddReference('AeccPressurePipesMgd')
clr.AddReference('acdbmgdbrep')
clr.AddReference('Civil3DNodes')
clr.AddReference('AutoCADNodes')

import Autodesk #Loads the Autodesk namespace
# Import references from AutoCAD
AAR = Autodesk.AutoCAD.Runtime
AAA = Autodesk.AutoCAD.ApplicationServices #Setting a handle to the currently-open instance of the AutoCAD application
AAD = Autodesk.AutoCAD.DatabaseServices
AAE = Autodesk.AutoCAD.EditorInput
AAG = Autodesk.AutoCAD.Geometry
AADy = Autodesk.AutoCAD.DynamoNodes

AUX = Autodesk.Aec.DatabaseServices

OP = AAD.OpenMode
TS = AAD.Transaction

# Import references from Civil3D
ACA = Autodesk.Civil.ApplicationServices #Setting a handle to the currently-open instance of the Civil3D application
ACD = Autodesk.Civil.DatabaseServices
ACDy = Autodesk.Civil.DynamoNodes

AD = ACA.CivilApplication.ActiveDocument #Finally, setting up handles to the active Civil3D document
AC = Autodesk.Civil

adoc = AAA.Application.DocumentManager.MdiActiveDocument
editor = adoc.Editor

#Inputs:
#IN[0] -> List of List of Civil Object

with adoc.LockDocument():
    with adoc.Database as db:

        with db.TransactionManager.StartTransaction() as t:
            # E vem ai:
          
            Ratio = 0.5
            Labels = []
            for i in range(0,len(IN[0])):
                for j in range(0,len(IN[0][i])):
                    Point = IN[0][i][j].InternalDBObject.Position
                    PT = AAG.Point3d(Point.X+6, Point.Y-5, Point.Z)
                    Labels.append(ACD.StructureLabel.Create(IN[0][i][j].InternalDBObject.Id,IN[1],PT))
                                       
            LabelsEx = TS.GetObject(t,Labels[0],OP.ForRead) 
            
            PColle = AAG.Point3dCollection()
            OBO = AAD.Intersect.OnBothOperands
            LabelsEx.BoundingBoxIntersectWith(IN[0][0][0].InternalDBObject,OBO,PColle,0,0)
            
            t.Commit()
            
# Assign your output to the OUT variable.
OUT = LabelsEx

1 Like

Hi @andre.demski,

I believe that BoundingBoxIntersectWith works on Autodesk.AutoCAD.DatabaseServices.DBObject and will not work with Civil Entities.
As a workaround, you may use Explode to get the block from the label and use it for your intersection check.


2 Likes

Oh, it makes a lot of sense, but I need the labels to remain labels so I can move them.

My idea is to make a routine which I create the labels, check if they have intersections with some other object and if so, I move them away from the interference.

So the idea I had after your answer is:

Create the label, explode, check the interferences and if there are interferences I delete the block, create the label again and so on…

Note that the labels will stay intact, the exploded objects will be in acDBObjColl. Try the above simple sample and you will get what I mean…

1 Like