.NET

Reply
Active Contributor
MGOMKD
Posts: 29
Registered: ‎06-23-2011
Message 11 of 31 (219 Views)

Re: How to get Block's Layer name?

07-30-2012 05:56 AM in reply to: Hallex

Hi Hallex,

 

I'm very surprised you're very quick! Thank you.

Now i have to understand code and work on it.

 

See you!

*Expert Elite*
Hallex
Posts: 1,558
Registered: ‎10-08-2008
Message 12 of 31 (217 Views)

Re: How to get Block's Layer name?

07-30-2012 06:55 AM in reply to: MGOMKD

Good to hear that,

Just a hint, you could be able to collect all of values of the particular subentity

into the

 List(Of (List (Of String))

( every single item inside into the List (of String)),

then this would be easier to write to the data file on another storage,

 

hth,

 

~'J'~

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Active Contributor
MGOMKD
Posts: 29
Registered: ‎06-23-2011
Message 13 of 31 (192 Views)

Re: How to get Block's Layer name?

08-08-2012 01:01 AM in reply to: Hallex

Hi Hallex, how are you?

 

I try de write the best code to obtain what i want but when i run it on AutoCAD, i have a dialog box error.

 

So in a module vars.

 

Module Paramètres

    '********************************'
    '* Paramètres du Document Actif *'
    '********************************'

    Public acDocs As DocumentCollection = Application.DocumentManager
    Public acDoc As Document = acDocs.MdiActiveDocument
    Public acCurDb As Database = acDoc.Database
    Public acTrans As Transaction
Public acBlkTbl As BlockTable
    Public acBlkTblRec As BlockTableRecord
End Module

 And the code

 

Sub ExcelApp(ByVal LayerVal)

        '***********************'
        '* Génération du fichier Excel *'
        '***********************'

Using acTrans = acCurDb.TransactionManager.StartTransaction() acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForRead)
For Each acObjId As ObjectId In acBlkTblRec Dim MyEnt As Entity = acTrans.GetObject(acObjId, OpenMode.ForRead) If MyEnt.Layer = LayerVal Then Select Case acObjId.ObjectClass.DxfName '******' '* ARC *' '******' Case Is = "ARC" Dim MyArc As AcadArc = CType(acTrans.GetObject(MyEnt.AcadObject, OpenMode.ForRead), AcadArc) MsgBox(MyArc.ArcLength) End If Next acObjId
End Using

 Error message: Impossible to cast type's object.

                          'Autodesk.AutoCAD.DatabaseServices.Arc' to 'Autodesk.AutoCAD.Interop.Common.AcadArc'

 

Am i on the right way?

Active Contributor
MGOMKD
Posts: 29
Registered: ‎06-23-2011
Message 14 of 31 (160 Views)

Re: How to get Block's Layer name?

08-09-2012 01:46 AM in reply to: MGOMKD

Hi all,

 

I just found what's wrong in my source code!

 

Change these lines:

 

Dim MyArc As AcadArc = CType(acTrans.GetObject(MyEnt.AcadObject, OpenMode.ForRead), AcadArc)
                     MsgBox(MyArc.ArcLength)

 by:

 

Dim MyArc As Autodesk.AutoCAD.DatabaseServices.Arc = TryCast(MyEnt, Entity)
MsgBox (MyArc.Length)

 Thanks to Hallex!

 

*Expert Elite*
Hallex
Posts: 1,558
Registered: ‎10-08-2008
Message 15 of 31 (157 Views)

Re: How to get Block's Layer name?

08-09-2012 02:07 AM in reply to: MGOMKD

Glad you solved it by yourself,

Happy coding :smileyhappy:

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Active Contributor
MGOMKD
Posts: 29
Registered: ‎06-23-2011
Message 16 of 31 (130 Views)

Re: How to get Block's Layer name?

08-17-2012 07:38 AM in reply to: Hallex

Hi,

 

I've met another matter!

When I iterate through specifics entities (like LWPOLYLINE, LINE, CIRCLE,...etc) sometimes my source code deal with "POINT". So I would like to cast it to obtain coordinates (X, Y, Z).

 

Dim MyPoint As Point3d = TryCast(MyEnt, Entity)

 

But the matter is I cannot access coordinate of these entity, cause Point3d belongs to Autodesk.AutoCAD.Geometry whereas MyEnt belong to AutoDesk.AutoCAD.DatabaseServices

 

How could I reach these informations?

 

*Expert Elite*
Hallex
Posts: 1,558
Registered: ‎10-08-2008
Message 17 of 31 (123 Views)

Re: How to get Block's Layer name?

08-17-2012 07:59 AM in reply to: MGOMKD

You could be able to get coordinates from polyline

with help of these functions:

 

''============================= LWPolyline =======================
 Public Shared Function getAllVertices(ByVal ent As Polyline) As Point2dCollection

    Dim verCollection As Point2dCollection = New Point2dCollection()
    Dim vertex As Point2d
    Dim i As Integer = 0
      For i = 0 To ent.NumberOfVertices - 1    
        vertex = ent.GetPoint2dAt(i)       
     verCollection.Add(vertex)    
    Next    
    Return verCollection  
  End Function
''============================= 3dPoly =======================
     Public Shared Function Get3dPolyVertices(ByVal poly3d As Polyline3d) As Point3dCollection  
            Dim pts As New Point3dCollection
            For i As Integer = 0 To poly3d.EndParam
                pts.Add(poly3d.GetPointAtParameter(i))
            Next i
        Return pts
    End Function

 From line you can get coordinates:

Dim sp as point3d= line.StartPoint

dim ep as point3d= line.EndPoint

 

same way for arc,circle etc

just find in Intellisence box appropriate properties for them all

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Active Contributor
MGOMKD
Posts: 29
Registered: ‎06-23-2011
Message 18 of 31 (119 Views)

Re: How to get Block's Layer name?

08-17-2012 08:21 AM in reply to: Hallex

Hi Hallex!

 

Always at the top!

 

I work on it, thanks a lot.

 

*Expert Elite*
Hallex
Posts: 1,558
Registered: ‎10-08-2008
Message 19 of 31 (103 Views)

Re: How to get Block's Layer name?

08-17-2012 09:40 PM in reply to: MGOMKD

:Glad to help

Cheers :smileyhappy

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Active Contributor
MGOMKD
Posts: 29
Registered: ‎06-23-2011
Message 20 of 31 (95 Views)

Re: How to get Block's Layer name?

08-18-2012 06:33 AM in reply to: Hallex

Hi Hallex,

 

I had found another way to obtain coords.

 

Case Is = "POINT"

                                    '*********'
                                    '* POINT *'
                                    '*********'
                               
                                    'Insertion du texte'
                                    acMText = New MText()
                                    Dim X as Double = MyEnt.GeometricExtents.MinPoint.X
                                    Dim Y as Double = MyEnt.GeometricExtents.MinPoint.Y
                                    Dim Z as Double = MyEnt.GeometricExtents.MinPoint.Z

                                    With acMText
                                        acMText.SetDatabaseDefaults()
                                        acMText.Location = New Point3d(X, Y, Z)
                                        acMText.Attachment = AttachmentPoint.BottomLeft
                                        acMText.TextHeight = acHeightText
                                        acMText.Contents = i
                                    End With

                                    acBlkTblRec.AppendEntity(acMText)
                                    acTrans.AddNewlyCreatedDBObject(acMText, True)

                                    'Libération de la variable'
                                    MyEnt = Nothing
                                    acMText = Nothing

 But what the difference between "MinPoint" and "MaxPoint"? I tried twice and it gaves the same result!

 

Thank You.

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community