Author Topic: extrude region from exploded block  (Read 9673 times)

0 Members and 1 Guest are viewing this topic.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4043
extrude region from exploded block
« on: January 05, 2007, 11:16:15 AM »
OK, I'm pulling my hair out, I am trying to create an extruded solid from a region, which is an exploded block. (My thought was to draw the region, and insert it as a block, then explode block, leaving the region I could then extrude.)  Should I be trying this, or use a polyline instead?  I guess I could draw a polyline based on coordinates from a single pick point, but that seemed like too much work. Or could I change my block from a region to a polyline, and extrude that?  Anyway, Im crashing when I try to capture the exploded block.  Is there a way to do this?
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4043
Re: extrude region from exploded block
« Reply #1 on: January 05, 2007, 11:22:33 AM »
I started with some other code, thus all the commented lines
Code: [Select]
Public Sub DrawWideFlangeSteel()

      Dim oCyl As Acad3DSolid, oCircle As AcadCircle, oLine As AcadLine, oLayer As AcadLayer
      Dim oBeam As Acad3DSolid, oReg As AcadRegion, oBlock As AcadBlockReference, oObject As AcadObject
      Dim varpick As Variant
      Dim Ent As AcadEntity
      Dim Inspt As Variant
      Dim RegEnt(0) As AcadEntity
      Dim V(2) As Double, Unit As Double, Vn(2) As Double, dblBusDia As Double
      Dim P1, P2
      Dim newPT1 As Variant
      Dim newPT2 As Variant
      Set oLayer = ThisDrawing.Layers.Add("3D-BUSS-STEEL")
      oLayer.color = 235
     
      Inspt = ThisDrawing.Utility.GetPoint(, "Pick Insertion Point: ")
      If ThisDrawing.ActiveSpace = acModelSpace Then
      Set oBlock = ThisDrawing.ModelSpace.InsertBlock(Inspt, "M:\MODEL-COMPONENTS\w8x24.dwg", 1#, 1#, 1#, 0)
      Else
      Set oBlock = ThisDrawing.PaperSpace.InsertBlock(Inspt, "M:\MODEL-COMPONENTS\w8x24.dwg", 1#, 1#, 1#, 0)
      End If
      ThisDrawing.Regen acActiveViewport
Set oObject = oBlock.Explode

'      ThisDrawing.Utility.GetEntity Ent, varpick
'      If Not TypeOf Ent Is AcadLine Then
'            MsgBox "That was not a Layout Line"
'            Exit Sub
'      End If
'      Set oLine = Ent
'      newPT1 = oLine.StartPoint
'      newPT2 = oLine.EndPoint
'      newPT1(2) = ConvertFeet(frmInsPart.cboBusHeight.Value)
'      newPT2(2) = ConvertFeet(frmInsPart.cboBusHeight.Value)
'      Set oLine = ThisDrawing.ModelSpace.AddLine(newPT1, newPT2)
'      oLine.Layer = "3D-BUSS-CALC"
'      P1 = oLine.StartPoint: P2 = oLine.EndPoint
'      V(0) = P2(0) - P1(0): V(1) = P2(1) - P1(1): V(2) = P2(2) - P1(2)
      'Normalise the vector(It's length=1)
'      Unit = Sqr(V(0) * V(0) + V(1) * V(1) + V(2) * V(2))
'      Vn(0) = V(0) / Unit: Vn(1) = V(1) / Unit: Vn(2) = V(2) / Unit
'      dblBusDia = CDbl(frmInsPart.cboBusSize.Value + 0.5) / 2
'      Set oCircle = ThisDrawing.ModelSpace.AddCircle(oLine.StartPoint, dblBusDia)
      ThisDrawing.Regen acActiveViewport
'      oCircle.Normal = Vn    ' Vn or V both work here.
'      ThisDrawing.Regen acActiveViewport
'      Set RegEnt(0) = oCircle
'      oReg = ThisDrawing.ModelSpace.AddRegion(RegEnt)
'      Set oCyl = ThisDrawing.ModelSpace.AddExtrudedSolid(oReg(0), oLine.Length, 0)
'      oCircle.Delete
'      oReg(0).Delete
End Sub
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

Jeff_M

  • King Gator
  • Posts: 4048
  • C3D user & customizer
Re: extrude region from exploded block
« Reply #2 on: January 05, 2007, 11:30:11 AM »
Whoa there, take a deep breath, relax.....there, now doesn't that feel better?

OK, now that we have you back, care to try again? Draw, Insert, Explode, Extrude......could you explain WHY you'd want to do it this way? What is your intent?

To get the objects of an exploded object:
Dim newObjs As Variant
newobjs = MyInsertedBlock.Explode
'Only 1 object in this block
Dim oEntity as AcadEntity
Set oEntity = newObjs(0)

And as I was composing this you posted the code that pretty much answered my questions.......but note how I get the exploded region.......

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4043
Re: extrude region from exploded block
« Reply #3 on: January 05, 2007, 11:59:52 AM »
Whoa there, take a deep breath, relax.....there, now doesn't that feel better?
Yes, much, thank you

OK, now that we have you back, care to try again? Draw, Insert, Explode, Extrude......could you explain WHY you'd want to do it this way? What is your intent?

Ok, long story short, Im in the process of creating a 3D substation design tool, that will help draw an electrical substation in 3d, and spit out a BOM, and stuff.  I was using 8" tube steel for most of my steel supports, but we sometimes use wide flange beams for the supports.  Once done, Im going to post it here for anyone interested in testing/use in the real world.
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4043
Re: extrude region from exploded block
« Reply #4 on: January 05, 2007, 12:46:18 PM »
Dim newObjs As Variant
newobjs = MyInsertedBlock.Explode
Is this where I went wrong?  I needed a variant to capture the exploded stuff?  I tried
Dim oSomething as AcadObject
oSomething = block.explode
which didn't work
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

Jeff_M

  • King Gator
  • Posts: 4048
  • C3D user & customizer
Re: extrude region from exploded block
« Reply #5 on: January 05, 2007, 01:14:22 PM »
Is this where I went wrong?  I needed a variant to capture the exploded stuff? 
Yep, that's it. And it will be an array of the objects in the block.

Fatty

  • Guest
Re: extrude region from exploded block
« Reply #6 on: January 05, 2007, 01:58:39 PM »
Sorry, Commandor
I think your main problem is on you
can't to create the region in other than XY WCS plane
First create region and then rotate3d it in desired
normal
Maybe I am wrong though :laugh:

~'J'~

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4043
Re: extrude region from exploded block
« Reply #7 on: January 05, 2007, 02:01:40 PM »
Thanks Jeff, I knew it could be done, I just couldn't find that piece of info
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4043
Re: extrude region from exploded block
« Reply #8 on: August 29, 2007, 11:01:57 AM »
OK, since I already started this thread, I figure I can continue here.  The above code is all fixed and working great.  I have a new issue in that I am creating 3 3dsolids, separately, and would like to union them together.
Code: [Select]
Public Sub AddDeadEnd(PhSpace As Double, PoleSp As Double, PoleHt As Double, BmHt As Double)
      Const VK_ESCAPE = &H1B
      Const VK_LBUTTON = &H1
      Const VK_SPACE = &H20
      Const VK_RETURN = &HD
      Const VK_LEFT = &H25
      On Err GoTo err_control
      Dim inspt As Variant, dblRotation As Double, dblTOC As Double, leftLeg As Variant, rightLeg As Variant
      Dim oCurrLayeR As AcadLayer, intAutoSnap As Integer, intOSMode As Integer, PI As Double, LL2 As Variant
      Dim oPline As AcadLWPolyline, oEntity(0) As AcadEntity, regent(0) As AcadEntity, obj3d As Acad3DSolid
      Dim objRegion
      Set oCurrLayeR = ThisDrawing.ActiveLayer
      'IsSetup
      dblTOC = CDbl(InputBox("What is T.O.C. elevation? ie 12 or 0 or -12"))
      ThisDrawing.SetVariable "ORTHOMODE", 1
      intAutoSnap = ThisDrawing.GetVariable("AUTOSNAP")
      ThisDrawing.SetVariable "AUTOSNAP", 0
      intOSMode = ThisDrawing.GetVariable("OSMODE")
      ThisDrawing.SetVariable "OSMODE", 32
      inspt = ThisDrawing.Utility.GetPoint(, "Select Deadend Insertion Point: ")
      ThisDrawing.SetVariable "OSMODE", 512
      dblRotation = ThisDrawing.Utility.GetAngle(inspt, "Pick Line Direction: ")
      PI = Atn(1) * 4

      ThisDrawing.SetVariable "OSMODE", 0
      inspt(2) = inspt(2) + dblTOC
      leftLeg = ThisDrawing.Utility.PolarPoint(inspt, dblRotation - ((PI * 90) / 180), PoleSp / 2)
      rightLeg = ThisDrawing.Utility.PolarPoint(inspt, dblRotation + ((PI * 90) / 180), PoleSp / 2)
      Call LayerSet("3D-STEL", 235)
      DrawDeadendPole leftLeg, PoleHt
      DrawDeadendPole rightLeg, PoleHt
      leftLeg(2) = leftLeg(2) + BmHt
      Set oPline = ThisDrawing.ModelSpace.AddLightWeightPolyline(PolygonVexs(leftLeg, 8, 5))
      oPline.Closed = True
      oPline.Elevation = BmHt
      oPline.Update
      Set regent(0) = oPline
      objRegion = ThisDrawing.ModelSpace.AddRegion(regent)
      Set obj3d = ThisDrawing.ModelSpace.AddExtrudedSolid(objRegion(0), PoleSp, 0)
      regent(0).Delete
      objRegion(0).Delete
     
      LL2 = ThisDrawing.Utility.PolarPoint(leftLeg, dblRotation, 12)
      obj3d.Rotate3D leftLeg, LL2, ((PI * -90) / 180)
Exit_Here:
      ThisDrawing.ActiveLayer = oCurrLayeR
      ThisDrawing.SetVariable "AUTOSNAP", intAutoSnap
      ThisDrawing.SetVariable "OSMODE", intOSMode
      ThisDrawing.SetVariable "INSUNITS", 1
      Exit Sub
err_control:
      Select Case Err.Number
      Case -2147352567
      'Debug.Print Err.Number, Err.Description
            varcancel = ThisDrawing.GetVariable("LASTPROMPT")
            If InStr(1, varcancel, "*Cancel*") <> 0 Then
                  If GetAsyncKeyState(VK_ESCAPE) And 8000 > 0 Then
                        Err.Clear
                        Resume Exit_Here
                  ElseIf GetAsyncKeyState(VK_LBUTTON) > 0 Then
                        Err.Clear
                        Resume
                  End If
            Else
                  If GetAsyncKeyState(VK_SPACE) Then
                        Resume Exit_Here
                  End If
      'Missed the pick, send them back!
                  Err.Clear
                  Resume
            End If
      Case Else
            MsgBox Err.Description
            Resume Exit_Here
      End Select
End Sub

DrawDeadendPole leftLeg and Right leg are the first 2 3d objs, the 3rd you can see at the bottom of the code.

the code for that is
Code: [Select]
Private Sub DrawDeadendPole(insptpole As Variant, PoleHt As Double)
      Dim dblBase As Double, dblTop As Double, dblHeight As Double
      Dim obj3d As Acad3DSolid, regent(0) As AcadEntity
      Dim oPline As AcadLWPolyline
      Dim cenPt As Variant, iNum As Integer, intAutoSnap As Integer
      Dim dblAng As Double, dblRad As Double, dblAngle As Double
      Dim objRegion

      dblHeight = PoleHt
      dblTop = 18 / 2
      dblAngle = Atn((dblTop - dblBase) / dblHeight)
      iNum = 12
      cenPt = insptpole
      dblRad = 29 / 2
      Set oPline = ThisDrawing.ModelSpace.AddLightWeightPolyline(PolygonVexs(cenPt, iNum, dblRad))
      oPline.ConstantWidth = 0
      oPline.Layer = "0"
      oPline.Closed = True
      oPline.Update
      Set regent(0) = oPline
      objRegion = ThisDrawing.ModelSpace.AddRegion(regent)
      Set obj3d = ThisDrawing.ModelSpace.AddExtrudedSolid(objRegion(0), dblHeight, dblAngle)
      regent(0).Delete
      objRegion(0).Delete
      ThisDrawing.Regen acActiveViewport

End Sub
Function PolygonVexs(cenPt As Variant, iNum As Integer, _
                     dblRad As Double, Optional mode As Integer = 0) As Variant
      Dim tmpPt As Variant
      Dim iCnt As Integer
      Dim vCnt As Integer
      Dim vxCnt As Integer
      Dim PI As Double
      PI = Atn(1) * 4
      Dim dltAng As Double
      Dim dblAng As Double
      Dim initAng As Double
      dltAng = 2 * PI / iNum
      initAng = dltAng / 2
      vxCnt = 2 * iNum - 1
      iCnt = 0
      vCnt = 0
      ReDim ptsarr(0 To vxCnt) As Double
      If mode = 0 Then dblRad = dblRad / Cos(dltAng / 2)
      While iCnt < iNum
            dblAng = initAng + dltAng * iCnt
            tmpPt = ThisDrawing.Utility.PolarPoint(cenPt, dblAng, dblRad)
            iCnt = iCnt + 1
            ptsarr(vCnt) = tmpPt(0): ptsarr(vCnt + 1) = tmpPt(1)
            vCnt = vCnt + 2
      Wend
      PolygonVexs = ptsarr
End Function


Anyway, the question is how can I capture the 3d solids as they are created to use the Boolean union later
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4043
Re: extrude region from exploded block
« Reply #9 on: August 29, 2007, 11:05:21 AM »
I tried making DrawDeadendPole a Function and using Set 3dobj=DrawDeadendPole
but that didn't work.  I might have been doing it wrong or didn't Dim the correct entity to begin with.  I'm thinking this is the way to go, I just haven't figured it out yet.
« Last Edit: August 29, 2007, 12:17:17 PM by CmdrDuh »
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

CADaver

  • Guest
Re: extrude region from exploded block
« Reply #10 on: August 29, 2007, 02:01:39 PM »
Side track...
1.)  You can extrude closed polylines, no need for region.
2.)  If you already have a block, just change the X or Z scale.

Pseudo code.
Collect profile data from file
Draw pline profile
Extrude profile one unit (X for beams or Z for cols.)
Add intelligence (attributes, xdata, whatever)
Makeblock
Insert block, modify X or Z to desired length and rotate.

X or Z values are extractable along with block name, location, layer, etc. with EATTEXT.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4043
Re: extrude region from exploded block
« Reply #11 on: August 29, 2007, 02:16:19 PM »
Cadaver, how do you extrude a closed polyline?  from the help file, it says region only
Quote
RetVal = object.AddExtrudedSolid(Profile, Height, TaperAngle)

Object

ModelSpace Collection, PaperSpace Collection, Block
The object or objects this method applies to.

Profile

Profile object; input-only
The Region object only.

Height

Double; input-only
The height of the extrusion along the Z axis of the object's coordinate system. If you enter a positive number, AutoCAD extrudes the object along the positive Z axis. If you enter a negative number, AutoCAD extrudes the object along the negative Z axis.

TaperAngle

Double; input-only
The taper angle of the extrusion must be provided in radians. The range of the taper angle is from -90 to +90 degrees.
Positive angles taper in from the base, negative angles taper out. The default angle, 0, extrudes a 2D object perpendicular to its plane.

RetVal

3DSolid object
A 3DSolid object as the newly created extruded solid.
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

Jeff_M

  • King Gator
  • Posts: 4048
  • C3D user & customizer
Re: extrude region from exploded block
« Reply #12 on: August 29, 2007, 03:56:18 PM »
Here's one way, Duh.
Code: [Select]
Private Function DrawDeadendPole(insptpole As Variant, PoleHt As Double) As Acad3DSolid
....all your code to create the solid
      objRegion(0).Delete
      ThisDrawing.Regen acActiveViewport
      Set DrawDeadendPole = obj3D
End Sub
Then in the calling Sub:
Code: [Select]
...blah blah blah
     Call LayerSet("3D-STEL", 235)
     Dim LeftPole as Acad3dSolid
     Dim RightPole as Acad3dSolid
      Set LeftPole = DrawDeadendPole(leftLeg, PoleHt)
      Set RightPole = DrawDeadendPole(rightLeg, PoleHt)
      leftLeg(2) = leftLeg(2) + BmHt
....more blah....
This will give you your 3 solids to Union

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4043
Re: extrude region from exploded block
« Reply #13 on: August 29, 2007, 04:01:50 PM »
I will have to give that a try.  Thanks Jeff
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4043
Re: extrude region from exploded block
« Reply #14 on: August 29, 2007, 04:08:26 PM »
That worked great!!!  I was so close, I was just missing a few things.  Thanks again Jeff
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second