Author Topic: Civil 3D Surfacing Help!  (Read 5840 times)

0 Members and 1 Guest are viewing this topic.

mpeterson79

  • Guest
Civil 3D Surfacing Help!
« on: November 15, 2007, 01:47:54 PM »
I'm looking for some help with automating our process of surface creation in Civil 3D 2008. Unfortunately, I'm pretty coding-dumb, so this isn't a straightforward, easy process like I envision it.

I've done some looking into example code using the developer's guides, but can't get anything to work.

If someone could provide some assistance, I'd greatly appreciate it.

What I envision this code doing:

1) Ask user to select feature line #1 (FL1)
2) Ask user to select feature line #2 (FL2)
3) Create a new TIN surface
  • with a name of Bldg 001 (number to increase with each additional surface)
  • on layer "Surface Bldgs" (existing in drawing as default TIN surface layer)
  • with surface style "Building Surfaces" (also default surface style)
4) The surface will be 'constructed' by first adding FL1 as a standard breakline. Second, FL2 will be added as a standard breakline and lastLy, FL2 will be added once again, but this time as a non-destructive boundary.

That's it - then on to select the next two feature lines to create the next surface (Bldg 002). Doesn't sound overly complicated, but I can't for the life of me figure it out.

Here's the code I assembled so far - it's pretty much all pilfered from the Developer's Guides.

Code: [Select]
(vl-load-com)

(setq AcadObject (vlax-get-acad-object))
(setq ActDoc (vla-get-activedocument AcadObject))
;;
;;
;; CODE TO CREATE SELECTION SET FL1 FOR EXTERIOR FEATURE LINE
;;
;;
Sub Ch4_CreateSelectionSet()
Dim selectionset1 as AcadSelectionSet
Set selectionset1 = ThisDrawing.SelectionSets.Add("FL1")
selectionset1.SelectOnScreen
End Sub
;;
;;
;; CODE TO CREATE SELECTION SET FL2 FOR INTERIOR FEATURE LINE
;;
;;
Sub Ch4_CreateSelectionSet()
Dim selectionset2 as AcadSelectionSet
Set selectionset2 = ThisDrawing.Selectionsets.Add("FL2")
selectionset2.SelectOnScreen
End Sub



;; CODE TO CREATE NEW SURFACE:
;;
;;
Dim TinSurface As AeccTinSurface
Dim Tindata as New AeccTinCreationData

TinData.Name = "Bldg Test" ;SET NAME OF SURFACE TO "BLDG"
;; need to add counter system for surface #
TinData.Description = "Building Surface from CPP Building datum" ;SET SURFACE DESCRIPTION
TinData.Layer = "Surface Bldgs" ;SET SURFACE LAYER
TinData.BaseLayer = "Surface Bldgs" ;NOT SURE WHAT THIS DOES
TinData.Style = "Building Surfaces" ;SET SURFACE STYLE
Set Tinsurface = AeccDocument.Surfaces.AddTinSurface(TinData) ;NOT SURE WHAT THIS DOES
;;
;;
;; CODE TO ADD THE EXTERIOR FEATURE LINE (FL1) AS A NON-DESTRUCTIVE BREAKLINE CODE TO THE SURFACE
;;
;;
set 3DPoly = AeccDocument.Database.Modelspace.Add3DPoly(dPoints)
3dPoly.Closed = False
Dim Breakline As AeCCSurfaceBreakline
Dim vBLines as Variant
Dim EntityArray(0) as AcadEntity
Set EntityArray(0) = AeccDocument.Database.ModelSpace.Add3DPoly(dPoints)
Set Breakline = TinSurface.Breaklines.AddNonDestructiveBreakline(EntityArray,"Exterior Non-Destructive Breakline", 1#)
;;
;;
;; ADD THE INTERIOR FEATURE LINE (FL2) AS A STANDARD BREAKLINE TO THE SURFACE(S1)
;;
;;
set 3DPoly = AeccDocument.Database.Modelspace.Add3DPoly(dPoints)
3dPoly.Closed = False
Dim Breakline As AeCCSurfaceBreakline
Dim vBLines as Variant
Dim EntityArray(0) as AcadEntity
Set EntityArray(0) = AeccDocument.Database.Modelspace.Add3DPoly
Set Breakline = TinSurface.Breaklines.AddStandardBreakline(EntityArray, "Exterior Boundary", 1#)
Dim EntityArray(0) as AcadEntity
Set EntityArray(0) = AeccDocument.Database.ModelSpace.Add3DPoly(dPoints)
Set Breakline = TinSurface.Breaklines.AddStandardBreakline(EntityArray, "Interior Breakline", 1#)
;;
;;
;; ADD THE EXTERIOR FEATURE LINE (FL1) AS A NON-DESTRUCTIVE BOUNDARY TO THE SURFACE(S1)
;;
;;
Dim Poly As AcadPolyline
Set Poly = AeccDocument.Database.ModelSpace.AddPolyLine(dPoints)
Poly.Closed = True

Dim sName as String
sName = "Surface Boundary"
Dim NewBoundary as AeccSurfaceBoundary
Set NewBoundary = Surface.Boundaries.Add(Poly, Sname, aeccBoundaryOuter, True, 0.5)

Can anyone help??
« Last Edit: November 15, 2007, 01:49:40 PM by mpeterson79 »

Bob Wahr

  • Guest
Re: Civil 3D Surfacing Help!
« Reply #1 on: November 15, 2007, 02:55:19 PM »
Sorry, I lack the software to play along.

Jeff_M

  • King Gator
  • Posts: 3948
  • C3D user & customizer
Re: Civil 3D Surfacing Help!
« Reply #2 on: November 15, 2007, 03:38:05 PM »
Could you post a sample drawing that has the plines before being added to a surface and the desired result (using different plines). Your code seems to be creating unnessessary objects.....but may be what you want.

Jeff_M

  • King Gator
  • Posts: 3948
  • C3D user & customizer
Re: Civil 3D Surfacing Help!
« Reply #3 on: November 15, 2007, 05:04:18 PM »
If this code doesn't do what you expect, then I'll need you to post that drawing. However, I think that this is what you want. Note that there is just a general error trap used, I highly recommend doing something a bit more robust.....

You will need to be sure to have the Civil Land & LandUI References set in the VBA project.
Code: [Select]
Sub test()
Dim oApp As AeccApplication
Dim oDoc As AeccDocument
Dim oSurfs As AeccSurfaces

Set oApp = Application.GetInterfaceObject("AeccXUiLand.AeccApplication.5.0")
Set oDoc = oApp.ActiveDocument
Set oSurfs = oDoc.Surfaces

Dim Tindata As New AeccTinCreationData

Tindata.Description = "Building Surface from CPP Building datum" 'SET SURFACE DESCRIPTION
Tindata.Layer = "Surface Bldgs"                 'SET SURFACE LAYER
Tindata.BaseLayer = "Surface Bldgs"             'NOT SURE WHAT THIS DOES
Tindata.Style = "Building Surfaces"             'SET SURFACE STYLE

Dim osurf As AeccSurface
Dim iCount As Integer
For Each osurf In oSurfs
    If osurf.Name Like "Bldg ###" Then
        Dim iTmp As Integer
        iTmp = CInt(Right(osurf.Name, 3))
        If iTmp > iCount Then iCount = iTmp
    End If
Next
Dim sCurName As String
Dim oEnt1 As AcadEntity
Dim oEnt2 As AcadEntity
Dim vPick As Variant

Dim oPoly1 As Acad3DPolyline
Dim opoly2 As Acad3DPolyline
Dim oEnts(0) As AcadEntity

Do Until Err.Number <> 0
    iCount = iCount + 1
    sCurName = "Bldg " & Format(iCount, "000")
    On Error GoTo ResumeHere
    ThisDrawing.Utility.GetEntity oEnt1, vPick, vbCr & "Select inside pline: "
    Set oPoly1 = oEnt1
    ThisDrawing.Utility.GetEntity oEnt2, vPick, vbCr & "Select outside pline: "
    Set opoly2 = oEnt2
    Tindata.Name = sCurName
    Dim oTinSurf As AeccTinSurface
    Set oTinSurf = oSurfs.AddTinSurface(Tindata)
    Set oEnts(0) = oPoly1
    oTinSurf.Breaklines.AddStandardBreakline oEnts, "Interior Breakline", 0.5
    Set oEnts(0) = opoly2
    oTinSurf.Breaklines.AddStandardBreakline oEnts, "Exterior Breakline", 0.5
    oTinSurf.Boundaries.Add opoly2, "Exterior Boundary", aeccBoundaryOuter, True, 0.5
ResumeHere:
'If Err Then MsgBox Err.Description ''uncomment to test for the error thrown
Loop

End Sub

mpeterson79

  • Guest
Re: Civil 3D Surfacing Help!
« Reply #4 on: November 16, 2007, 10:20:49 AM »
Jeff - thank you tremendously for your help.

With your code, I'm currently erroring out at the line:

Code: [Select]
Set oApp = Application.GetInterfaceObject("AeccXUiLand.AeccApplication.5.0")
I've attached a dwg which will hopefully explain better what I'm trying to do. I need to build a surface using the two feature lines as breaklines, and then also using the outer feature line as a boundary. I'm using Civil 3D 2008, if that makes any difference.

Jeff_M

  • King Gator
  • Posts: 3948
  • C3D user & customizer
Re: Civil 3D Surfacing Help!
« Reply #5 on: November 16, 2007, 11:38:45 AM »
A couple things to look at....

First, what is the error being thrown? I'm also using 2008-SP2, do you have any SP's installed?

Second, I see that your drawing has Featurelines. There is a bug/deficiency in the API (yes, it's been logged by Adesk) that does not allow us to add breaklines using Featurelines. One way around this is to use the lisp (vlax-curve-*)  functions to extract the coordinates of each PI and create a temporary 3dpoly. Another would be to explode your Featurelines first, thereby leaving 3dpoly's, if the FL has differing elevations for the PI's, or LWPoly's, if the PI's are all identical, in their place (this cannot be done in code, either, as nothing is exposed in the API for FL's).

I'm attaching the DVB that works for me with your drawing's FL's exploded.

mpeterson79

  • Guest
Re: Civil 3D Surfacing Help!
« Reply #6 on: November 16, 2007, 02:42:54 PM »
Jeff,

Everything works fantastic now that I loaded your newest DVB file.

I was afraid that the feature lines may cause problems, but I can work around that. I liked using the feature lines for their dynamic update capability, but the time savings of your code easily trumps any savings I had with the dynamic capabilities of the feature lines. On the rare occasion that we used the feature lines to update a surface, we can now simply recreate the surface definition.

Thanks ever so much for your help with this - this truly is a time saver.

Mark

Jeff_M

  • King Gator
  • Posts: 3948
  • C3D user & customizer
Re: Civil 3D Surfacing Help!
« Reply #7 on: November 16, 2007, 04:11:19 PM »
You're welcome, Mark! Glad I could help.

Just remember to test in any newer versions whether you can use Featurelines. Since Adesk knows of the problem, there's a good chance it will be addressed in the next version or two. To test, just comment out the 2, 3-line, sections of code and change the references & InterfaceObject. (We won't know what these will be in the future releases, but if history is any indicator then I'd wager that the 2009 version will use Land 6.0.) But that's still a ways off......

mpeterson79

  • Guest
Re: Civil 3D Surfacing Help!
« Reply #8 on: May 08, 2008, 06:34:39 PM »
You're welcome, Mark! Glad I could help.

Just remember to test in any newer versions whether you can use Featurelines. Since Adesk knows of the problem, there's a good chance it will be addressed in the next version or two. To test, just comment out the 2, 3-line, sections of code and change the references & InterfaceObject. (We won't know what these will be in the future releases, but if history is any indicator then I'd wager that the 2009 version will use Land 6.0.) But that's still a ways off......

Well, 2009 is here, and alas, being the code-tard that I am, I can't get this code to run any more. I've changed the line:
Code: [Select]
Set oApp = Application.GetInterfaceObject("AeccXUiLand.AeccApplication.5.0")

to now read:

Code: [Select]
Set oApp = Application.GetInterfaceObject("AeccXUiLand.AeccApplication.6.0")

And I get a runtime error '13' - Type mismatch.

Can someone shed some light on what I'm doing wrong?

Jeff_M

  • King Gator
  • Posts: 3948
  • C3D user & customizer
Re: Civil 3D Surfacing Help!
« Reply #9 on: May 08, 2008, 07:06:39 PM »
Welcome back, Mark.

I can only surmize that you probably have both 2008 & 2009 installed and you have not changed the reference to reflect the 2009 version under Tools/References. So when you Dim oApp As AeccApplication it is trying to use the 2008 libraries but then trying to set it to the 2009 version.

mpeterson79

  • Guest
Re: Civil 3D Surfacing Help!
« Reply #10 on: June 24, 2010, 03:11:40 PM »
And so in C3D 2011 (which I just installed this morning, and am currently fumbling through it's pitfalls), more problems arise.

Now when I invoke the command, I get an error message saying
Quote
Compile Error:
User-defined type not defined

for the second line of code that is:
Code: [Select]
Dim oApp As AeccApplication
Some Googling tells me there's a reference error, but I don't understand a) what a reference is, or b) how to resolve the issue for 2011.

Here's the full code I'm currently using:
Code: [Select]
Sub test()
Dim oApp As AeccApplication
Dim oDoc As AeccDocument
Dim oSurfs As AeccSurfaces

Set oApp = Application.GetInterfaceObject("AeccXUiLand.AeccApplication.7.0")
Set oDoc = oApp.ActiveDocument
Set oSurfs = oDoc.Surfaces

Dim Tindata As New AeccTinCreationData

Tindata.Description = "Building Surface from CPP Building datum" 'SET SURFACE DESCRIPTION
Tindata.Layer = "Surface Bldgs"                 'SET SURFACE LAYER
Tindata.BaseLayer = "Surface Bldgs"             'NOT SURE WHAT THIS DOES
Tindata.Style = "Building Surfaces"             'SET SURFACE STYLE

Dim osurf As AeccSurface
Dim iCount As Integer
For Each osurf In oSurfs
    If osurf.Name Like "BLDG ###" Then
        Dim iTmp As Integer
        iTmp = CInt(Right(osurf.Name, 3))
        If iTmp > iCount Then iCount = iTmp
    End If
Next
Dim sCurName As String
Dim oEnt1 As AcadEntity
Dim oEnt2 As AcadEntity
Dim vPick As Variant

Dim oEnts(0) As AcadEntity

Do Until Err.Number <> 0
    iCount = iCount + 1
    sCurName = "BLDG " & Format(iCount, "000")
    On Error GoTo ResumeHere
    ThisDrawing.Utility.GetEntity oEnt1, vPick, vbCr & "Select inside pline: "
    Dim sOtype As String
    sOtype = UCase(oEnt1.ObjectName)
    If Not ((sOtype Like "*POLY*") Or (sOtype Like "*FEATURE*")) Then
        Err.Raise -4444444, , "Incorrect object type selected!"
        GoTo ResumeHere
    ''Remove the ElseIf section when the API allows Featurelines
    ElseIf sOtype Like "*FEATURE*" Then
        Err.Raise -4444445, , "Featurelines not currently supported, explode and try again!"
        GoTo ResumeHere
    End If
    ThisDrawing.Utility.GetEntity oEnt2, vPick, vbCr & "Select outside pline: "
    sOtype = UCase(oEnt2.ObjectName)
    If Not ((sOtype Like "*POLY*") Or (sOtype Like "*FEATURE*")) Then
        Err.Raise -4444444, , "Incorrect object type selected!"
        GoTo ResumeHere
    ''Remove the ElseIf section when the API allows Featurelines
    ElseIf sOtype Like "*FEATURE*" Then
        Err.Raise -4444445, , "Featurelines not currently supported, explode and try again!"
        GoTo ResumeHere
    End If
    Tindata.Name = sCurName
    Dim oTinSurf As AeccTinSurface
    Set oTinSurf = oSurfs.AddTinSurface(Tindata)
    Set oEnts(0) = oEnt1
    oTinSurf.Breaklines.AddStandardBreakline oEnts, "Interior Breakline", 0.5
    Set oEnts(0) = oEnt2
    oTinSurf.Breaklines.AddStandardBreakline oEnts, "Exterior Breakline", 0.5
    oTinSurf.Boundaries.Add oEnt2, "Exterior Boundary", aeccBoundaryOuter, True, 0.5
ResumeHere:
Select Case Err.Number
    Case Is = -4444444
        MsgBox Err.Description
    Case Is = -4444445
        MsgBox Err.Description
    Case Else
'        MsgBox Err.Description ''uncomment to test for the error thrown, comment out to run normally
End Select
Loop

End Sub

Can anyone shed some light on what I'm missing again?

Jeff_M

  • King Gator
  • Posts: 3948
  • C3D user & customizer
Re: Civil 3D Surfacing Help!
« Reply #11 on: June 25, 2010, 09:48:53 AM »
Are you using the 64-bit version of 2011? If so, the C3D Interops don't get registered during the install. I'll attach the REG file to this post which you can run to install them. If not, disregard this part...

In the VBAIDE, go to the Tools menu, choose References, deselect anything that has to do with Civil, scroll down to the Civil 8.0 libraries and select the 2 Land related items.

mpeterson79

  • Guest
Re: Civil 3D Surfacing Help!
« Reply #12 on: June 28, 2010, 10:31:44 AM »
Thanks Jeff_M - that did the trick.

I'm only running 32bit right now, but should be on a new machine with 64bit Win7 by the end of the week, so that REG file will come in handy.

sinc

  • Guest
Re: Civil 3D Surfacing Help!
« Reply #13 on: June 28, 2010, 11:06:08 AM »
I have been told that, with C3D 2011 x64, simply loading the VBA module slows down the entire program considerably.  You may end up needing to convert your routine to .NET.