AutoCAD Civil 3D Customization

AutoCAD Civil 3D Customization

Reply
Valued Contributor
kcimos
Posts: 91
Registered: ‎02-18-2010
Message 1 of 16 (1,095 Views)
Accepted Solution

vb.net 2012 (cogo) point styles

1095 Views, 15 Replies
10-11-2012 04:38 PM

all I want to do is get the point style from a user selected COGO point (& then later set it to a different one). This point might be selected along with lines, blocks, and/or whatever. I can get to where I'm dealing with the POINTENTITYobject but one can't access the style from that (or can we?). From what I gather I need to set am AECCPOINT variable from the pointentity object, using the pointentity number property as an index for the aeccpointS index method. THing is, I can't get the AECCPOINTS collection. with is a part of the civil database.

after much research I have the following relevent code:

    Dim PtNumber As Double
    Dim ePoint As PointEntity
    Dim aPoint As AeccPoint
    Dim aPoints As AeccPoints
    Dim aPointsIds As ObjectIdCollection

 

 

    Private m_oAeccDb As IAeccDatabase


    <CommandMethod("CDE")> _
    Public Sub ChangeToDemoCivil()        'this is the civil3d version, which works on COGO point styles too










        ACF.SsGetStuff("Select objects to be placed onto DEMO layers:")

        Dim idArray As ObjectId() = ACF.ssResult.GetObjectIds()

        For Each id As ObjectId In idArray

            Using acTrans As Transaction = ACF.Db.TransactionManager.StartTransaction()


                Try

                    ePoint = CType(acTrans.GetObject(id, OpenMode.ForWrite), PointEntity)


                    If Not ePoint Is Nothing Then        'it is a cogo point, so change to appropriate demo style

                        PtNumber = ePoint.PointNumber


                        aPoints = m_oAeccDb.Points

 ACF.getstuff () is an external funtion that stores a list of objectids of selected objects in  ACF.ssResult (as Autodesk.AutoCAD.EditorInput.SelectionSet)

 

I am getting a fatal error on this:

 

aPoints = m_oAeccDb.Points

 

 

You don't need to go about it in that fashion. See if this helps:

 

 Dim ss() As ObjectId = ssResult.Value.GetObjectIds()
Dim ptEnt As PointEntity
Using tr As Transaction = doc.Database.TransactionManager.StartTransaction()
For Each objId As ObjectId In ss
ptEnt = objId.GetObject(OpenMode.ForRead, False)
Dim ptObj As AeccLandLib.AeccPoint = ptEnt.AcadObject
Dim ptStyle As AeccLandLib.AeccPointStyle = ptObj.Style
doc.Editor.WriteMessage("Name of the selected point's syle is: " + ptStyle.Name)
Next
End Using

 

Here's how to test for the existence of a PointLabelStyle:

 Function PointLabelStyleExists(ByVal civDoc As CivilDocument, ByVal name As String) As Boolean
PointLabelStyleExists = False
Dim styles As Autodesk.Civil.DatabaseServices.Styles.LabelStyleCollection = civDoc.Styles.LabelStyles.PointLabelStyles.LabelStyles
Try
Dim id As ObjectId = styles(name)
PointLabelStyleExists = True
Catch ex As ArgumentException
End Try
End Function

 

To copy a pointstyle (assuming you have the existing style ObjectId as id):

 Using tr As Transaction = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction()
Dim style As PointStyle = TryCast(id.GetObject(OpenMode.ForRead, False, True), PointStyle)
Dim newId As ObjectId = style.CopyAsSibling(style.Name + " - (Copy)")
tr.Commit()
End Using

 

As for the point style marker, use the MarkerType and MarkerSymbolName properties of the style object.

 

See here for more info: http://docs.autodesk.com/CIV3D/2012/ENU/API_Reference_Guide/net/html/2953dd7d-c44a-9c3a-7fa0-74a3fef39159.htm

*Expert Elite*
Jeff_M
Posts: 4,521
Registered: ‎07-22-2003
Message 2 of 16 (1,083 Views)

Re: vb.net 2012 (cogo) point styles

10-11-2012 07:56 PM in reply to: kcimos

You don't need to go about it in that fashion. See if this helps:

 

            Dim ss() As ObjectId = ssResult.Value.GetObjectIds()
            Dim ptEnt As PointEntity
            Using tr As Transaction = doc.Database.TransactionManager.StartTransaction()
                For Each objId As ObjectId In ss
                    ptEnt = objId.GetObject(OpenMode.ForRead, False)
                    Dim ptObj As AeccLandLib.AeccPoint = ptEnt.AcadObject
                    Dim ptStyle As AeccLandLib.AeccPointStyle = ptObj.Style
                    doc.Editor.WriteMessage("Name of the selected point's syle is: " + ptStyle.Name)
                Next
            End Using

 

Jeff_M, also a frequent Swamper
Valued Contributor
kcimos
Posts: 91
Registered: ‎02-18-2010
Message 3 of 16 (1,073 Views)

Re: vb.net 2012 (cogo) point styles

10-12-2012 05:40 AM in reply to: kcimos

"Dim ptObj As AeccLandLib.AeccPoint = ptEnt.AcadObject"

 

that was the key bit of info I needed.

 

I never would have thouht that a PointEntity had AcadObject property which had a Style property. Now I can look into this aspect of the civil 3d object model, and probably gain enlightenment to other bizarre things.

 

thanks

Valued Contributor
kcimos
Posts: 91
Registered: ‎02-18-2010
Message 4 of 16 (1,063 Views)

Re: vb.net 2012 (cogo) point styles

10-12-2012 11:27 AM in reply to: kcimos

OK, now how can I access the point's label style?

Valued Contributor
kcimos
Posts: 91
Registered: ‎02-18-2010
Message 5 of 16 (1,062 Views)

Re: vb.net 2012 (cogo) point styles

10-12-2012 11:28 AM in reply to: kcimos

OK, I figured that out, I had to go bask to the PointEntity object

Valued Contributor
kcimos
Posts: 91
Registered: ‎02-18-2010
Message 6 of 16 (1,059 Views)

Re: vb.net 2012 (cogo) point styles

10-12-2012 11:45 AM in reply to: kcimos

opps sorry, its under PointEntity.AcadObject

Valued Contributor
kcimos
Posts: 91
Registered: ‎02-18-2010
Message 7 of 16 (1,052 Views)

Re: vb.net 2012 (cogo) point styles

10-12-2012 02:40 PM in reply to: kcimos

OK, now I'm trying work out how to test if a point style exists.

All I can find is a similar method that was causing my initial post, for getting the pointstyles from the document this time, which crashes.

 

I'm looking at the civil3d 2012 developers guide's section on COM

& so to try to retrofit my code to fit with their examples, I add this:

Dim oAcadApp As AcadApplication
Set oAcadApp = ThisDrawing.Application
' Specify the COM name of the object we want to access.
' Note that this always accesses the most recent version
' of AutoCAD Civil 3D installed.
Const sCivilAppName = "AeccXUiLand.AeccApplication.6.0"
Dim oCivilApp As AeccApplication
Set oCivilApp = oAcadApp.GetInterfaceObject(sCivilAppName)
 
' Now we can use the AeccApplication object.
' Get the AeccDocument representing the currently
' active drawing.
Dim oDocument As AeccDocument
Set oDocument = oCivilApp.ActiveDocument
' Set the viewport of the current drawing so that all
' drawing elements are visible.
oCivilApp.ZoomExtents

 & the first error is that acadapplication is ambigous in the autodesk.autocad.interop

then I see that they are using "THISDRAWING" & "SET". so this documentation for COM is based on VBA, which makes sense, except VB.NET is what the guide is about.

 

so, anyone know of any way to test if a (point) style exists?

 

(anyway of copying or saving as one too?)

 

*Expert Elite*
Jeff_M
Posts: 4,521
Registered: ‎07-22-2003
Message 8 of 16 (1,048 Views)

Re: vb.net 2012 (cogo) point styles

10-12-2012 03:17 PM in reply to: kcimos

I prefer to stay with the .NET API when possible. This will check if a PointStyle exists. Use the same idea for other styles.

 

    Function PointStyleExists(ByVal civDoc As CivilDocument, ByVal name As String) As Boolean
        Dim exists As Boolean = False
        Dim styles As PointStyleCollection = civDoc.Styles.PointStyles
        Try
            Dim id As ObjectId = styles(name)
            exists = True
        Catch ex As ArgumentException
        End Try
        PointStyleExists = exists
    End Function

 Or, depending on what you need it for, have it return the ObjectId if you need that.

Jeff_M, also a frequent Swamper
*Expert Elite*
Jeff_M
Posts: 4,521
Registered: ‎07-22-2003
Message 9 of 16 (1,044 Views)

Re: vb.net 2012 (cogo) point styles

10-12-2012 04:07 PM in reply to: kcimos

kcimos wrote:

 

(anyway of copying or saving as one too?)

 


Not sure I understand this question.

Jeff_M, also a frequent Swamper
*Expert Elite*
Jeff_M
Posts: 4,521
Registered: ‎07-22-2003
Message 10 of 16 (1,040 Views)

Re: vb.net 2012 (cogo) point styles

10-12-2012 04:21 PM in reply to: Jeff_M

Here's how to test for the existence of a PointLabelStyle:

    Function PointLabelStyleExists(ByVal civDoc As CivilDocument, ByVal name As String) As Boolean
        PointLabelStyleExists = False
        Dim styles As Autodesk.Civil.DatabaseServices.Styles.LabelStyleCollection = civDoc.Styles.LabelStyles.PointLabelStyles.LabelStyles
        Try
            Dim id As ObjectId = styles(name)
            PointLabelStyleExists = True
        Catch ex As ArgumentException
        End Try
    End Function

 

Jeff_M, also a frequent Swamper
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.