Author Topic: (C3D '08) Add Multiple Boundaries (VBA)  (Read 3358 times)

0 Members and 1 Guest are viewing this topic.

Guest

  • Guest
(C3D '08) Add Multiple Boundaries (VBA)
« on: August 17, 2007, 01:06:59 PM »
I'm trying to write a simple (should be) program to add multiple boundaries to a surface.  It bombs out here on this line (x.Add obj...) with an Object Variable or With Block Variable Not Set error message.

Maybe it's because it's Friday....maybe it's too much caffeine, but I can't get this thing worked out and I KNOW it's something stupid-simple.

Code: [Select]
Option Explicit


Public Sub AddMultipleBoundaries()
    Dim x As AeccSurfaceBoundaries
    Dim ssSet As AcadSelectionSet
    Dim FilterType(0) As Integer
    Dim FilterData(0) As Variant
    Dim obj As AcadEntity
    Dim i As Integer
   
    Set ssSet = vbdPowerSet("Boundaries")
       
    FilterType(0) = 0
    FilterData(0) = "lwpolyline"
   
    ssSet.SelectOnScreen FilterType, FilterData
   
    i = 1
    For Each obj In ssSet
        x.Add obj, "Boundary " & i, aeccBoundaryHide, True, 1#
        i = i + 1
    Next obj
End Sub


Public Function vbdPowerSet(strName As String) As AcadSelectionSet
    Dim objSelSet As AcadSelectionSet
    Dim objSelCol As AcadSelectionSets
   
    Set objSelCol = ThisDrawing.SelectionSets
    For Each objSelSet In objSelCol
        If objSelSet.Name = strName Then
            objSelSet.Delete
            Exit For
        End If
    Next
    Set objSelSet = ThisDrawing.SelectionSets.Add(strName)
    Set vbdPowerSet = objSelSet
End Function

mjfarrell

  • Seagull
  • Posts: 14444
  • Every Student their own Lesson
Re: (C3D '08) Add Multiple Boundaries (VBA)
« Reply #1 on: August 17, 2007, 01:32:52 PM »
is it possible, that you need an entry in there to name those bounds?
Be your Best


Michael Farrell
http://primeservicesglobal.com/

Guest

  • Guest
Re: (C3D '08) Add Multiple Boundaries (VBA)
« Reply #2 on: August 17, 2007, 01:56:24 PM »
This would be the boundary names: Boundary " & i

Jeff_M

  • King Gator
  • Posts: 4098
  • C3D user & customizer
Re: (C3D '08) Add Multiple Boundaries (VBA)
« Reply #3 on: August 17, 2007, 02:03:57 PM »
Hint: The Add method expects an array of objects......oh, and they can't be featurelines....

Edit: Found my sample code to do this... {Edit - This has absolutely nothing to do with the question being asked...use it for future reference when you want to add breaklines, though.  :oops: thanks for catching that, sinc.}
Code: [Select]
    'assumes you have a valid Surface object at this point, oSurface
     Create the selection set
    Dim SSet As AcadSelectionSet
    Dim SSEnt As AcadEntity
    On Error Resume Next
    Set SSet = ThisDrawing.SelectionSets.Add("myset")
    If Err Then Set SSet = ThisDrawing.SelectionSets.Item("myset")
    Err.Clear
    On Error GoTo 0
    Dim gpCode(1) As Integer
    Dim gpValue(1) As Variant
    gpCode(0) = 0
    gpValue(0) = "*POLYLINE"
    gpCode(1) = 8
    gpValue(1) = "WORK-3D-BRKLINES"
    SSet.Select acSelectionSetAll, , , gpCode, gpValue
    MsgBox SSet.Count & " objects on the layer."

    ' Add the entities in the selection set
    Dim entDesc As String
    Dim midOrd As Double
    entDesc = "Breaklines added by VBA"
    midOrd = 0.1
    If SSet.Count > 0 Then
        Dim oBrkObjs() As Object
        ReDim oBrkObjs(0 To SSet.Count - 1)
        Dim I As Integer
        For Each SSEnt In SSet
            If SSEnt.ObjectName Like "*Feature*" Then
                Set SSEnt = SSEnt.Explode
            End If
            Set oBrkObjs(I) = SSEnt
            I = I + 1
        Next SSEnt
        oSurface.Breaklines.AddStandardBreakline oBrkObjs, entDesc, midOrd
    End If
« Last Edit: August 17, 2007, 06:09:03 PM by Jeff_M »

Jeff_M

  • King Gator
  • Posts: 4098
  • C3D user & customizer
Re: (C3D '08) Add Multiple Boundaries (VBA)
« Reply #4 on: August 17, 2007, 02:08:17 PM »
In addition to the method I showed, you could add each one individually by slightly modifying the code I posted.

sinc

  • Guest
Re: (C3D '08) Add Multiple Boundaries (VBA)
« Reply #5 on: August 17, 2007, 06:04:52 PM »
Jeff's code is adding breaklines instead of boundaries, but the crux is similar for boundaries.

There's a routine in the SincpacC3D that does exactly this (add multiple hide boundaries to a surface), if you can translate the C#.NET to VBA...

http://www.ejsurveying.com/sincpacc3d.htm

The surface won't let you add a boundary if it already has one with the given name, so I put an exception handler around that part that skips to the next higher-number and tries again.

Jeff_M

  • King Gator
  • Posts: 4098
  • C3D user & customizer
Re: (C3D '08) Add Multiple Boundaries (VBA)
« Reply #6 on: August 17, 2007, 06:09:58 PM »
All I can say is it's a good thing it's Friday. Hey, at least they both start with a B, so I was close.

Jeff_M

  • King Gator
  • Posts: 4098
  • C3D user & customizer
Re: (C3D '08) Add Multiple Boundaries (VBA)
« Reply #7 on: August 17, 2007, 06:36:07 PM »
Sorry Matt,
After looking at your code for what you are really trying to do, all I can see wrong is that you are not assigning X to a surface Boundaries collection. Converting your code to a Function that accepts a valid surface as an argument, this works:
Code: [Select]
Function AddMultipleBoundaries(oSurface As AeccTinSurface)
    Dim x As AeccSurfaceBoundaries
    Dim ssSet As AcadSelectionSet
    Dim FilterType(0) As Integer
    Dim FilterData(0) As Variant
    Dim obj As AcadEntity
    Dim i As Integer
   
    Set x = oSurface.Boundaries
    Set ssSet = vbdPowerSet("Boundaries")
       
    FilterType(0) = 0
    FilterData(0) = "lwpolyline"
   
    ssSet.SelectOnScreen FilterType, FilterData
   
    i = 1
    For Each obj In ssSet
        x.Add obj, "Boundary " & i, aeccBoundaryHide, True, 1#
        i = i + 1
    Next obj
End Function
HTH,
Have a good weekend

Guest

  • Guest
Re: (C3D '08) Add Multiple Boundaries (VBA)
« Reply #8 on: August 20, 2007, 08:30:07 AM »
Jeff:
Thanks for the heads up with the surface.

However, when I add this to a sub AddMultipleBoundaries "EG" <-- EG being the surface name, I get a Type Mismatch error.  Should I NOT be passing it the name of the surface?

Jeff_M

  • King Gator
  • Posts: 4098
  • C3D user & customizer
Re: (C3D '08) Add Multiple Boundaries (VBA)
« Reply #9 on: August 20, 2007, 10:57:50 AM »
Hi Matt,
The function expects the surface object, not the surface's name.....we could change that if you want, though.