Author Topic: aeccpoint insert  (Read 3716 times)

0 Members and 1 Guest are viewing this topic.

jcoon

  • Newt
  • Posts: 157
aeccpoint insert
« on: September 09, 2011, 01:21:15 PM »


Trying to insert a aeccpoint at the selected screen location but I keep getting an error at
Set oPoints = g_oDocument.Points ''''''''''''''''''error here. It's a copy from the help files? so why desn't it
generate an object

thanks
john



Option Explicit
Public g_oCivilApp As AeccApplication
Public g_oDocument As AeccDocument
Public g_oAeccDatabase As AeccDatabase
Public AeccApp As AeccApplication
Public AeccDoc As AeccDocument
Public AeccDb As AeccDatabase
Public doc As AcadDocument

Private Sub CommandButton19_Click()

hide
' Always get the objects again since MDI is supported.
   If (GetBaseCivilObjects() = False) Then
        Exit Sub
    End If

Dim basePnt As Variant
Dim oPoints As AeccPoints
Dim oPoint1 As AeccPoint
Dim dLocation(0 To 2) As Double
   
basePnt = ThisDrawing.Utility.GetPoint(, "Select Location to Label")
         
dLocation(0) = basePnt(0)
dLocation(1) = basePnt(1)
dLocation(2) = 0#

Set oPoints = g_oDocument.Points ''''''''''''''''''error here
Set oPoint1 = oPoints.Add(dLocation)

'oPoint1.Number = 1000000
'oPoint1.Name = "point1"
'oPoint1.RawDescription = "Point Description"
'oPoint1.Update
 
opoint.update


UserForm1.Show
End Sub

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: aeccpoint insert
« Reply #1 on: September 09, 2011, 02:09:33 PM »
And that error would be ???? Also, is the g_oDocument getting set correctly iow, is it a valid object when trying to set the Points object)?
« Last Edit: September 09, 2011, 02:13:34 PM by Jeff_M »

jcoon

  • Newt
  • Posts: 157
Re: aeccpoint insert
« Reply #2 on: September 10, 2011, 03:22:32 PM »

Jeff,

I was getting an error saying with block variable not set at the Set oPoint = g_oDocument.Points.Add(dLoc). I tested it at home
and removed the Public settings and it worked fine. I'm not sure why removing the public setting would do that after being set in the module1 but my sample works fine now.

would you happen to have sample that does the same as below but in vb dot net or one that draws a simple line alignment.

as always thanks for helping me think this out.
john 


Private Sub CommandButton20_Click()
hide
    ' Check to make sure Civil 3D is running and get the Civil objects
    If (GetBaseCivilObjects = False) Then
        Exit Sub
    End If
   
    Dim dLoc(0 To 2) As Double
    Dim oPoints As AeccPoints
    Dim oPoint As AeccPoint
   
       
dLoc(0) = 100: dLoc(1) = 100: dLoc(2) = 100#
Set oPoint = g_oDocument.Points.Add(dLoc)
oPoint.Update


UserForm1.Show

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: aeccpoint insert
« Reply #3 on: September 10, 2011, 10:03:42 PM »
HI John, if the Public Objects were also Dim'ed in another module, VBA doesn't like that IIRC.

Here are 3 examples for: Setting a point using COM, adding an alignment to the siteless alignments using COM and another for .NET

Code: [Select]

Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.Civil
Imports Autodesk.Civil.ApplicationServices
Imports Autodesk.Civil.Land.DatabaseServices
Imports Autodesk.AECC.Interop.Land
Imports Autodesk.AECC.Interop.UiLand
Imports Autodesk.Civil.Land.DatabaseServices.Styles



Public Class Class1

    <CommandMethod("MySetPoint")> _
    Public Sub MySetPoint()

        Dim aeccapp As AeccApplication = New AeccApplicationClass()
        aeccapp.Init(Application.AcadApplication)
        Dim aeccdoc As AeccDocument = aeccapp.ActiveDocument
        Dim pt As Point3d = New Point3d(100.0, 100.0, 100.0)
        Dim aeccpt As AeccPoint = aeccdoc.Points.Add(pt.ToArray())
        aeccapp = Nothing

    End Sub

    <CommandMethod("MyAddAlignCOM")> _
    Public Sub MyAddAlignCOM()
        Dim aeccapp As AeccApplication = New AeccApplicationClass()
        aeccapp.Init(Application.AcadApplication)
        Dim aeccdoc As AeccDocument = aeccapp.ActiveDocument
        Dim alignstyle As AeccAlignmentStyle = aeccdoc.AlignmentStyles(0) ''get the first style in the collection
        Dim alignlblstyle As AeccAlignmentLabelStyleSet = aeccdoc.AlignmentLabelStyleSets(0) ''get the first label style set in the collection
        Dim layer As String = aeccdoc.Settings.DrawingSettings.ObjectLayerSettings.AlignmentLayer.Layer
        Dim aeccalign As AeccAlignment = aeccdoc.AlignmentsSiteless.Add("MyFirstAlign", "0", alignstyle, alignlblstyle)
        Dim pt1 As Point3d = New Point3d(100.0, 100.0, 100.0)
        Dim pt2 As Point3d = New Point3d(300.0, 100.0, 100.0)
        aeccalign.Entities.AddFixedLine1(pt1.ToArray(), pt2.ToArray())
        aeccapp = Nothing
    End Sub

    <CommandMethod("MyAddAlignNET")> _
    Public Sub MyAddALignNET()
        Dim civdoc As CivilDocument = CivilApplication.ActiveDocument
        Dim alignstyle As ObjectId = civdoc.Styles.AlignmentStyles(0)
        Dim alignlblstyle As ObjectId = civdoc.Styles.LabelSetStyles.AlignmentLabelSetStyles(0)
        Dim layer As ObjectId = civdoc.Settings.DrawingSettings.ObjectLayerSettings.GetObjectLayerSetting(Autodesk.Civil.Settings.SettingsObjectLayerType.Alignment).LayerId
        Dim alignid As ObjectId = Alignment.Create(civdoc, "MyFirstNETAlign", ObjectId.Null, layer, alignstyle, alignlblstyle)
        Using tr As Transaction = Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction()
            Dim pt1 As Point3d = New Point3d(100.0, 100.0, 100.0)
            Dim pt2 As Point3d = New Point3d(300.0, 100.0, 100.0)
            Dim align As Alignment = tr.GetObject(alignid, OpenMode.ForWrite)
            align.Entities.AddFixedLine(pt1, pt2)
            tr.Commit()
        End Using
    End Sub
End Class

jcoon

  • Newt
  • Posts: 157
Re: aeccpoint insert
« Reply #4 on: September 12, 2011, 07:55:44 AM »
Jeff,

I didn't know that VBA didn't like the IIRC. I just copied some old sectons of code to make this one time routine and never thought about the public dims.
I guess I've been lucky because I never encountered it before.

Thank you so much for the dot net samples.  I've tried a few times to find the time to move my routines to dot net but work always seems to get crazy when I'm in the middle of learning dot net, then it's a month later and I've forgotten everything I had worked out the month before. 
I've struggled mostly with debugging, when trying to debug in dot net I crash so my times because I don't understand how to catch the dot net error's right it becomes frustrating having to launch autocad again and again as I crash my system........In time I'll get there.

as always, thank you for you help and understanding. I know it's not easy having to deal with beginner questions all the time.

John