draw a Cogo point by vba

draw a Cogo point by vba

Anonymous
Not applicable
3,856 Views
18 Replies
Message 1 of 19

draw a Cogo point by vba

Anonymous
Not applicable

Hello Every body

One can not help me?

I want to draw a Cogo point in Autocad Civil 3d by VBA

 

Thank you for your attention

0 Likes
Accepted solutions (1)
3,857 Views
18 Replies
Replies (18)
Message 2 of 19

Jeff_M
Consultant
Consultant
Look for the Samples in the C3D install folder, there are a few VBA samples. Use these to see how you get the AeccLand* objects, the Civil document, and it's AeccPoints collection. Once you have that, just call the Add(XYZ) method (where XYZ is an array of 3 doubles).
Jeff_M, also a frequent Swamper
EESignature
Message 3 of 19

Anonymous
Not applicable

 

I could not find
I do not know where is the problem.
Are you able to send these files or copy that code for me? (please)

0 Likes
Message 4 of 19

Anonymous
Not applicable

Ooo ... Yes ...

I Found ...

But when i use this Code in new form :

 

Call CreatePoints

System error displays :

Object variable or with block variable not set

 

1.jpg

2.jpg

0 Likes
Message 5 of 19

Jeff_M
Consultant
Consultant
Is the code which sets the g_oDocument object being run prior to this?
Jeff_M, also a frequent Swamper
EESignature
Message 6 of 19

Anonymous
Not applicable

Can you explain a little more?

Frankly , I do not know anything about the " g_oDocument" 😕

I upload my code : aminbadrkhaniasl.gigfa.com/Project.dvb

can you check it Please ?

0 Likes
Message 7 of 19

Jeff_M
Consultant
Consultant
Sorry, I cannot check it as I do not have VBA installed, and I have no intention of installing it. If you started with one of those sample projects it should show how you call the function which sets that variable to the AeccCivilDocument.
Jeff_M, also a frequent Swamper
EESignature
Message 8 of 19

Anonymous
Not applicable
Accepted solution
Dim oApp As AcadApplication
Set oApp = ThisDrawing.Application
Const sAppName = "AeccXUiLand.AeccApplication.11.0"
Set g_oCivilApp = oApp.GetInterfaceObject(sAppName)
Set g_oDocument = g_oCivilApp.ActiveDocument

Dim oPoints As AeccPoints
Set oPoints = g_oDocument.Points

Dim oPoint1 As AeccPoint
point(0) = "0": point(1) = "0": point(2) = "0"
ThisDrawing.ModelSpace.AddPoint point

Set oPoint1 = oPoints.Add(point)
oPoint1.Name = "point1"
Message 9 of 19

Anonymous
Not applicable

I would like to do a similar situation with creating a COGO point by vba, but I have a userform where the point number, northing, easting, elevation, and description (drawing template file has description keys set for different point sytles and label styles) are entered. I understand how to write the location of the point (x,y,z), but I don't understand how to get the point number and description to come in?

 

0 Likes
Message 10 of 19

hippe013
Advisor
Advisor

"and I have no intention of installing it"

Smiley LOL Smiley LOL Smiley LOL

0 Likes
Message 11 of 19

Jeff_M
Consultant
Consultant

When you Add() the point it returns teh CogoPoint object. Just set the PointNumber and RawDescription properties for the point.

 

@hippe013 , you liked that, huh? Smiley Very Happy

Jeff_M, also a frequent Swamper
EESignature
0 Likes
Message 12 of 19

Anonymous
Not applicable

Hi Jeff,

 

I pieced together the following code, but I am getting an error of "Run-error 13: Type mismatch" at "Set oPoints = g_oDocument.Points". I am missing something but I cant figure it out.

 

Private Sub cmdInsert_Click()
Dim oApp As AcadApplication
Set oApp = ThisDrawing.Application
Const sAppName = "AeccXUiLand.AeccApplication.10.4"
Set g_oCivilApp = oApp.GetInterfaceObject(sAppName)
Set g_oDocument = g_oCivilApp.ActiveDocument

Dim oPoints As AeccPoints
Set oPoints = g_oDocument.Points

Dim oPoint1 As AeccPoint
Dim oPoint(0 To 2) As Double
oPoint(0) = txtE: oPoint(1) = txtN: oPoint(2) = txtZ
ThisDrawing.ModelSpace.AddPoint point

Set oPoint1 = oPoints.Add(point)
oPoint1.Name = txtName
End Sub

 

0 Likes
Message 13 of 19

hippe013
Advisor
Advisor

This is just a shot in the dark here, but try:

Dim g_oDocument As AeccDocument
Set g_oDocument = g_oCivilApp.ActiveDocument

Otherwise it appears that it is returning an AcadDocument

 

AeccApplication.PNG

 

https://knowledge.autodesk.com/support/civil-3d/learn-explore/caas/CloudHelp/cloudhelp/2017/ENU/Civi...

 

Hope that this helps.

Message 14 of 19

Jeff_M
Consultant
Consultant

Looks like @hippe013 saw the same thing I was going to suggest.

I also saw something that will throw an error once you get past that first issue. You create an oPoint array but use point in the 2 calls to create points.

Dim oPoint1 As AeccPoint
Dim point(0 To 2) As Double
point(0) = txtE: point(1) = txtN: point(2) = txtZ
ThisDrawing.ModelSpace.AddPoint point ''This serves zero purpose, remove it, unless you want an AutoCAD Point object at the same location as your C3D point object.

Set oPoint1 = oPoints.Add(point)
Jeff_M, also a frequent Swamper
EESignature
Message 15 of 19

Anonymous
Not applicable

Hi..thanks for your advice and input. I see where I went wrong. I needed to call for the C3d points.

 

I did some searching and found this topic and it works to create COGO points by vba. It is just the references and autocad version needs to be updated. For 2015 the 3.0 needs to change to 10.4. Below is the link to the forum and to code that is used:

 

https://forums.autodesk.com/t5/autocad-land-desktop-read-only/create-point-in-c3d-vba/td-p/1442263

 

Here is a quick little bit of code that will add a single point at 0,0. Make
sure that you add references to the two Civil Engineering type libraries.

Option Explicit

Public g_oCivilApp As AeccApplication
Public g_oAeccDoc As AeccDocument
Public g_oAeccDb As AeccDatabase

Function getCivilObjects() As Boolean
Dim oApp As AcadApplication

Set oApp = ThisDrawing.Application
Const sAppName = "AeccXUiLand.AeccApplication.3.0"
Set g_oCivilApp = oApp.GetInterfaceObject(sAppName)
If g_oCivilApp Is Nothing Then
MsgBox "Error creating " & sAppName & ", exit."
getCivilObjects = False
Exit Function
End If
Set g_oAeccDoc = g_oCivilApp.ActiveDocument
Set g_oAeccDb = g_oAeccDoc.Database
getCivilObjects = True
End Function

Public Sub AddPoint()
getCivilObjects

Dim cPts As AeccPoints
Dim cgPt As AeccPoint
Dim pt(0 To 2) As Double

Set cPts = g_oAeccDb.Points
Set cgPt = cPts.Add(pt)
End Sub

0 Likes
Message 16 of 19

Anonymous
Not applicable

I would like to create a button on the userform to go to C3D model space and then using the mouse to click on the screen to create a point at that location. I can create the button to hide the form but i am not sure how to place a point at the mouse location. Will I need to first find the mouse pixel coordinates and then convert the coordinates to the drawing coordinates? Or can this be done similar to inserting a block?

0 Likes
Message 17 of 19

Jeff_M
Consultant
Consultant
Just use the getpoint method as you would to insert a block or draw a line. (Sorry, I don't recall the actual name used for that in VBA...it's been too long since using VBA)
Jeff_M, also a frequent Swamper
EESignature
0 Likes
Message 18 of 19

Anonymous
Not applicable

I ended up revising some of this code to make it work for me. I created a form where a button is clicked to go to model space and to click on an existing node in the drawing. Once the node is click it does update the form with the Northing, Easting, Elevation, but I cant seem to get the Point Number and the Point Description to populate in the form. Is it possible to bring the Point Number and Point Description into the form?

 

Private Sub cmdGetNode2_Click()

frmCTRL_QA.Hide

Dim application As Object
Dim AutoCAD As acadapplication
Dim acadapplication As Object
Dim acadapp As Object
Dim activedocument As Object
Dim Thisdrawing As Object
Dim Initializeuserinput As Object
Dim modelspace As Object

Dim insertionPnt(0 To 2) As Double
On Error Resume Next
Set acadapp = GetObject(, "AutoCAD.Application")
If Err Then
Err.Clear
Set acadapp = CreateObject("AutoCAD.Application")
AutoCAD.application.Visible = True
If Err Then
MsgBox Err.Description & Err.Number
Exit Sub
End If
End If
'Dim quarg
On Error Resume Next
Set acadapp = GetObject(, "autocad.application")
Set Thisdrawing = acadapp.activedocument
acadapp.Visible = True
''Apptivate
'Me.Show

With Thisdrawing.Utility

.Initializeuserinput 1
InsertionPoint = Thisdrawing.Utility.GetPoint(, vbCr & "insertion point: ")

frmCTRL_QA.txtN.Text = InsertionPont.Number
frmCTRL_QA.txtN.Text = Round(Str(InsertionPoint(0)), 3)
frmCTRL_QA.txtE.Text = Round(Str(InsertionPoint(1)), 3)
frmCTRL_QA.txtZ.Text = Round(Str(InsertionPoint(2)), 3)


End With

Me.show

End Sub

0 Likes
Message 19 of 19

Jeff_M
Consultant
Consultant
A few things...why are you setting the acadapp variable twice? You are not yet creating the CogoPoint, so there is no point number or description to use.

Once you have the InsertionPoint, use it in the Add method of the Points collection of the civil drawing database, just as you showed you found in a previous post.
Jeff_M, also a frequent Swamper
EESignature
0 Likes