How to find and export Object Classess from drawing

How to find and export Object Classess from drawing

Sgear
Advocate Advocate
1,028 Views
6 Replies
Message 1 of 7

How to find and export Object Classess from drawing

Sgear
Advocate
Advocate

 

Hi

 

How can I  make report to excel from the drawing need to find all Class name I have in the drawing and get name and length and export

 

I use Object Classess to draw line

Sample

Class name "4 Fiber"

Class name "12 Fiber"

 

Regards
Sgear

 

 

0 Likes
1,029 Views
6 Replies
Replies (6)
Message 2 of 7

Sgear
Advocate
Advocate

 

 

I am finish fo find out how I can count how many line I have but I realy need the line Length and how I can select 

 

the command work when I am finish but I need to select 4fiber before = ThisDrawing.SendCommand("(command

 

anyone who can help me with this

 

 

 

         Dim pfSS As AcadSelectionSet
            Dim ssobject As AcadEntity


            Dim LineCount As Integer
            LineCount = 0
            Dim LineLength As Double
            LineLength = 0

            Dim AcApp As Autodesk.AutoCAD.Interop.AcadApplication = DirectCast(Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication, Autodesk.AutoCAD.Interop.AcadApplication)
            Dim ThisDrawing As Autodesk.AutoCAD.Interop.AcadDocument = AcApp.ActiveDocument

            ThisDrawing.SendCommand("(command ""MAPSELECTCLASSIFIED"" ""4fiber"")" & vbCr)

            pfSS = ThisDrawing.PickfirstSelectionSet


            LineCount = LineCount + pfSS.Count

    
            For Each ssobject In pfSS



            Next ssobject

            '   pfSS.Highlight(True)

            MsgBox(LineCount)
            MsgBox(LineLength)

            pfSS.Delete()

 

0 Likes
Message 3 of 7

Sgear
Advocate
Advocate

Finish to fix Line length

 

how can I select the Polyline in code is it the command MAPSELECTCLASSIFIED ? or 

 

ThisDrawing.SendCommand "(command ""MAPSELECTCLASSIFIED"" 4fiber& vbCr

 

 

  Dim oEntline As AcadLWPolyline


         For Each oEnt In pfSS
                If TypeOf oEnt Is AcadLWPolyline Then

                    oEntline = oEnt
                    LineLength = LineLength + oEnt.Length
                End If
            Next oEnt
0 Likes
Message 4 of 7

norman.yuan
Mentor
Mentor

Please realize that this forum is for vanilla AutoCAD .NET API discussion. If your question is specific for certain AutoCAD vertical product, other forum might provide better responds; or at least you give some information on what AutoCAD product your question is related to. I was guessing your question is about AutoCAD Map/Civil3D because of the mentioning of "class", but only was certain after seeing your following questions.

 

Anyway, here is my answer to your question.

 

AutoCAD Map (Civil3D) come with .NET Map ObjectARX APIs, which covers APIs do manipulate classification data. So, you do not use SendCommand()/SendStringToExecute() to call an AutoCAD Map command. In the Map .NET API there is class called ClassificationManager, which you can use to find classified entities easily.

 

In order to use Map .NET API, you need to set reference to ManagedMapApi.dll. You can download AutoCAD Map ObjectARX SDK (not AutoCAD ObjectARX SDK), so that you can take llok at the documentation and sample code on how to use MAP .NET API (to deal with classification, map query, map data import/export...)

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 5 of 7

Sgear
Advocate
Advocate

 

Thanks will check the documentation and sample

 

I am using Autocad Map 2015 and Visual Studio Express 2013 Finish to get Map ObjectARX SDK

 

I am try to use the sample 🙂  with out the form only get No classified entity

 

 

 

      Dim errorCode As Classification.FeatureClassErrorCode = Classification.FeatureClassErrorCode.OK
        Try
            Dim colIds As ObjectIdCollection = Nothing
            Try
    
                Dim Getclass As String
                Getclass = "4fiber"

     
                colIds = m_ClassificationManager.GetClassifiedEntities(Getclass.ToString(), True)

            Catch e As System.Exception
                Utility.ShowMsg(vbNewLine & "No classified entity." & vbNewLine)
                Return
            End Try

            'Highlight the entities.
            Dim colId As ObjectId
            For Each colId In colIds
                HighLightEnt(True, colId)
            Next colId

 

0 Likes
Message 6 of 7

norman.yuan
Mentor
Mentor

It is really difficult to say why you did not get any entities back from call ClassificationManager.GetClassifiedEntities(string, bool) without seein gyour drawing file opened in AutoCAD Map.

 

However, from your first post, the class name seems "4 fiber", not "4fiber".

 

You may call ClassificationManager.GetFeatureClassNames(), and loop through each class name to decide which one is the target class name.

 

Or you can call ClassificationManager.GetClassifiedEntities()  (the method that does not take any input parameter) to see if there is any entity returned.

 

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 7 of 7

Sgear
Advocate
Advocate

 

 

Hi

 

Thanks manage to get this to work 

 

in the ClassificationVB sample

 

I was try to select all object class it hightlight but it only select the polyline I add last time not all

 

Autodesk.AutoCAD.Internal.Utils.SelectObjects(ids)

 

 

    Private Sub HighLightEnt(ByVal isHighLight As Boolean, ByVal objId As ObjectId)
            Dim IDNAME As Object
            IDNAME = 0
            Dim colIds As ObjectIdCollection = Nothing
            Dim subEntId As Autodesk.AutoCAD.DatabaseServices.SubentityId = New Autodesk.AutoCAD.DatabaseServices.SubentityId(SubentityType.Null, 0)
            Dim ids(1) As Autodesk.AutoCAD.DatabaseServices.ObjectId
            ids(0) = objId
            Dim path As Autodesk.AutoCAD.DatabaseServices.FullSubentityPath = New Autodesk.AutoCAD.DatabaseServices.FullSubentityPath(ids, subEntId)
            Dim ent As Entity = Nothing
            Dim trans As Transaction = Nothing
            Try
                trans = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.TransactionManager.StartTransaction()
                ent = trans.GetObject(objId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead)
                If Not ent Is Nothing Then
                    If isHighLight Then
                        ent.Highlight(path, True)
               
                        IDNAME = objId.ToString
                     
                        Utility.ShowMsg(IDNAME)

                        Autodesk.AutoCAD.Internal.Utils.SelectObjects(ids)

                    Else
                        ent.Unhighlight(path, True)
                    End If
                    trans.Commit()
                End If
            Catch
                Utility.ShowMsg(vbNewLine & "ObjectIdToObject Error")
            Finally
                trans.Dispose()
            End Try
        End Sub
0 Likes