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

0 Members and 2 Guests are viewing this topic.

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Re: extrude region from exploded block
« Reply #15 on: August 29, 2007, 04:20:54 PM »
You're welcome, I'm glad I could help!

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: extrude region from exploded block
« Reply #16 on: December 05, 2007, 12:52:39 AM »
Hi All,

I have to knock out a quick modeling app similar to this, I don't have time to do it in a LL language and it will be more of a prototype to be ported later if all works well.

Anyway, I've borrowed some of Duh's code and I have a small problem, I have a library of shapes as polylines already to go, what I want to do is insert the polyline as a block, explode it to get the polyline and extrude it but I'm getting a 'self reference' error, here's the code so far.
Code: [Select]
Public Sub DrawSection()
      Dim oLayer As AcadLayer
      Dim oBeam As Acad3DSolid, oReg As AcadRegion, oBlock As AcadBlockReference, oObject As Variant
      Dim Inspt As Variant
      Dim RegEnt(0) As AcadEntity

      Set oLayer = ThisDrawing.Layers.Add("3D-mbr")
      oLayer.color = 235
     
      Inspt = ThisDrawing.Utility.GetPoint(, "Pick Insertion Point: ")
     
      Set oBlock = ThisDrawing.ModelSpace.InsertBlock(Inspt, "C:\DCS3d\310UB040.dwg", 1#, 1#, 1#, 0) '<--self ref error here

      ThisDrawing.Regen acActiveViewport
      Set oObject = oBlock.Explode
      ThisDrawing.Regen acActiveViewport
      Set RegEnt(0) = oObject
      oReg = ThisDrawing.ModelSpace.AddRegion(RegEnt)
      Set oBeam = ThisDrawing.ModelSpace.AddExtrudedSolid(oReg(0), 1000, 0)
      oReg(0).Delete
End Sub

Once I get this sorted I will add code to look up the file by name and let the user select the appropriate section, add some data to it for BOM's and manipulation and transform it into it's final place.

tia,
Mick.
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

SEANT

  • Bull Frog
  • Posts: 345
Re: extrude region from exploded block
« Reply #17 on: December 05, 2007, 05:55:22 AM »
I can’t recreate that error here (AutoCAD 2004), even with the C:\DCS3d\310UB040.dwg active. :?

Generating the appropriate solid, however,  wouldn't happen until modifications (see earlier post by Jeff_M) were made to these lines of code:

      oObject = oBlock.Explode  '<---------------------
      ThisDrawing.Regen acActiveViewport
      Set RegEnt(0) = oObject(0) '<---------------------
      oReg = ThisDrawing.ModelSpace.AddRegion(RegEnt)
      Set oBeam = ThisDrawing.ModelSpace.AddExtrudedSolid(oReg(0), 1000, 0)
« Last Edit: December 05, 2007, 06:55:44 AM by SEANT »
Sean Tessier
AutoCAD 2016 Mechanical

kpblc

  • Bull Frog
  • Posts: 396
Re: extrude region from exploded block
« Reply #18 on: December 05, 2007, 07:13:07 AM »
Try this one (i didn't test it):
Code: [Select]
Public Function DrawSection(Optional DWGPath As String = "c:\DCS3d", _
  Optional DWGName As String = "310UB040") As AcadObject
' DWGPath - path to dwg-file (w/o splash)
' DWGName - file name w/o extension
' There is no control for these parameters
Dim objLayer As AcadLayer, objBeam As Acad3DSolid, objRegion As AcadRegion
Dim objBlockRef As AcadBlockReference, objBlockExplode As Variant
Dim ptInsert As Variant, lCounter As Long

  Set objLayer = ThisDrawing.Layers.Add("3D-mbr")
  objLayer.color = 235
On Error Resume Next
  objLayer.Freeze = False
  objLayer.Lock = False
  ptInsert = ThisDrawing.Utility.GetPoint(, "Pick Insertion Point <Cancel> : ")
  If IsEmpty(ptInsert) Or Err.Number <> 0 Then Exit Function
  If ThisDrawing.Blocks.Item(DWGName) Is Nothing Then
    Set objBlockRef = ThisDrawing.ModelSpace.Insertnblock(ptInsert, _
      DWGPath & "\" & DWGName & ".dwg", 1#, 1#, 1#, 0#)
  Else
    Set objBlockRef = ThisDrawing.ModelSpace.Insertnblock(ptInsert, _
      DWGName, 1#, 1#, 1#, 0#)
  End If
  objBlockExplode = objBlockRef.Explode
  objBlockRef.Delete
  For lCounter = LBound(objBlockExplode) To UBound(objBlockExplode)
    If objBlockExplode(lCounter).ObjectName = "AcDbRegion" Then
      objRegion = objBlockExplode(lCounter)
      Exit For
    End If
  Next lCounter
  Set objBeam = ThisDrawing.ModelSpace.AddExtrudedSolid(objRegion, 1000#, 0)
  objRegion.Delete
  DrawSection = objBeam
End Function
Sorry for my English.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: extrude region from exploded block
« Reply #19 on: December 05, 2007, 02:38:46 PM »
Hi All,

I have to knock out a quick modeling app similar to this, I don't have time to do it in a LL language and it will be more of a prototype to be ported later if all works well.

Anyway, I've borrowed some of Duh's code and I have a small problem, I have a library of shapes as polylines already to go, what I want to do is insert the polyline as a block, explode it to get the polyline and extrude it but I'm getting a 'self reference' error, here's the code so far.
Code: [Select]
Public Sub DrawSection()
      Dim oLayer As AcadLayer
      Dim oBeam As Acad3DSolid, oReg As AcadRegion, oBlock As AcadBlockReference, oObject As Variant
      Dim Inspt As Variant
      Dim RegEnt(0) As AcadEntity

      Set oLayer = ThisDrawing.Layers.Add("3D-mbr")
      oLayer.color = 235
     
      Inspt = ThisDrawing.Utility.GetPoint(, "Pick Insertion Point: ")
     
      Set oBlock = ThisDrawing.ModelSpace.InsertBlock(Inspt, "C:\DCS3d\310UB040.dwg", 1#, 1#, 1#, 0) '<--self ref error here

      ThisDrawing.Regen acActiveViewport
      Set oObject = oBlock.Explode
      ThisDrawing.Regen acActiveViewport
      Set RegEnt(0) = oObject
      oReg = ThisDrawing.ModelSpace.AddRegion(RegEnt)
      Set oBeam = ThisDrawing.ModelSpace.AddExtrudedSolid(oReg(0), 1000, 0)
      oReg(0).Delete
End Sub

Once I get this sorted I will add code to look up the file by name and let the user select the appropriate section, add some data to it for BOM's and manipulation and transform it into it's final place.

tia,
Mick.
Did you get it to 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.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: extrude region from exploded block
« Reply #20 on: December 05, 2007, 04:24:24 PM »
@SEANT - I did have that code in there, I changed the oObject(0) though with no improvement.

@kpblc - thanks for that but it's still not working, I commented out On Error resume next to catch a bug and it gives a 'key not found' error at the line -> If ThisDrawing.Blocks.Item(DWGName) Is Nothing Then

And thanks for the function, you have anticipated my future needs well ;)

@CmdrDuh - not yet, I didn't mention that I was using 2007, I didn't think it mattered until I found a thread where you had the same trouble but I tried adding the file string to a variable but had the same result.

I'll keep playing and see what I can come up with, thanks.

P.S. - with all examples, after I stop the code I do not have the block listed in the dlg when I do a manual insert so the block ref isn't in the table still, I tried adding a block to the table first but it was no better.
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

kpblc

  • Bull Frog
  • Posts: 396
Re: extrude region from exploded block
« Reply #21 on: December 05, 2007, 05:10:34 PM »
That's right - if there is no block named DWGName in file this line will generate a error.
Sorry for my English.

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: extrude region from exploded block
« Reply #22 on: December 05, 2007, 05:27:26 PM »
That's right - if there is no block named DWGName in file this line will generate a error.

Ok, do you mean that I have to create a block inside the file 310UB040.dwg called 310UB040 ?
At the moment it is a polyline in a drg file, I want to insert the file as a block, explode it to get the polyline the use the polyline for the extrusion.
I just tried to make a block inside the dwg file but no good, I also purged the block from the file so it was just the polyline too.
I'm missing something simple I think.
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

kpblc

  • Bull Frog
  • Posts: 396
Re: extrude region from exploded block
« Reply #23 on: December 05, 2007, 06:05:46 PM »
Quote
do you mean that I have to create a block inside the file 310UB040.dwg called 310UB040 ?
No! Never! To 'erase' a error with commented line you should have a block named 310UB040 in current drawing. In 'empty' dwg you haven't it, right? Because of this you should insert a file 'like a block'. At second calling this vba-routine you've got a block definition, so you just insert getted block definition (to exclude a error 'duplicate block definition').
Sorry for my English.

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: extrude region from exploded block
« Reply #24 on: December 05, 2007, 06:07:48 PM »
Ok, with this code below -
Code: [Select]
  If ThisDrawing.Blocks.Item(DWGName) Is Nothing Then
    Set objBlockRef = ThisDrawing.ModelSpace.Insertnblock(ptInsert, _
      DWGPath & "\" & DWGName & ".dwg", 1#, 1#, 1#, 0#)
  Else
    Set objBlockRef = ThisDrawing.ModelSpace.Insertnblock(ptInsert, _
      DWGName, 1#, 1#, 1#, 0#)
  End If

wouldn't the first 'if' generate a block named "c:\DCS3d\310UB040.dwg"
and the second 'Else' is looking for just "310UB040" ???
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Re: extrude region from exploded block
« Reply #25 on: December 05, 2007, 06:28:32 PM »
Well it would, or should anyway, if you spelled InsertBlock without the second "n" :-)

I'm seriuosly looking now though.....

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: extrude region from exploded block
« Reply #26 on: December 05, 2007, 06:40:38 PM »
heh, I haven't been that far through the code yet :)

I can't believe that the help doc's does not have an example of inserting a block from a drg file?? I would've thought that the idea of block, write once use many times not to create them through code!?

I actually got the old code to insert the block, it still breaks on the explode line but when I stop the debug I'm leaft with a block and a polyline ??

thanks Jeff.

edit - If I just insert the block, no prob's, I'll look a bit closer at the explode method
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: extrude region from exploded block
« Reply #27 on: December 05, 2007, 06:47:17 PM »
Ok, so acad strips the path and the file ext., that's good to know.
forget my previous post.
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Re: extrude region from exploded block
« Reply #28 on: December 05, 2007, 06:55:49 PM »
Mick,
This works for me....although I'd think you'd probably want to delete the BlockRef & Polyline once you have the Solid.
Code: [Select]
Option Explicit
Public Sub DrawSection()
      Dim oLayer As AcadLayer
      Dim oBeam As Acad3DSolid, oReg As Variant, oBlock As AcadBlockReference, oObject As Variant
      Dim Inspt As Variant
      Dim RegEnt(0) As AcadEntity
      Set oLayer = ThisDrawing.Layers.Add("3D-mbr")
      oLayer.color = 235
     
      Inspt = ThisDrawing.Utility.GetPoint(, "Pick Insertion Point: ")
     
      Set oBlock = ThisDrawing.ModelSpace.InsertBlock(Inspt, "C:\DCS3d\310UB040.dwg", 1#, 1#, 1#, 0) '<--self ref error here

      'ThisDrawing.Regen acActiveViewport
      oObject = oBlock.Explode
      'ThisDrawing.Regen acActiveViewport
      Set RegEnt(0) = oObject(0)
      oReg = ThisDrawing.ModelSpace.AddRegion(RegEnt)
      Set oBeam = ThisDrawing.ModelSpace.AddExtrudedSolid(oReg(0), 1000, 0)
      oReg(0).Delete
End Sub

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: extrude region from exploded block
« Reply #29 on: December 05, 2007, 07:03:39 PM »
Excellent Jeff!
I almost had kpblc's code working too, I've compared notes and should be able to work it out, I'll post when done.
thanks again.
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien