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

0 Members and 1 Guest are viewing this topic.

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: extrude region from exploded block
« Reply #30 on: December 05, 2007, 07:35:53 PM »
The finished product, I left out the layer stuff to keep it clear. I also took off the return value as it cause an error when the OnResnext jump was commented out, I guess there could be a work around like not assigning the objBeam to the db in the function and let the caller add it, I will experiment.

Code: [Select]
Public Function DrawSection(Optional DWGPath As String = "c:\DCS3d", _
                                Optional DWGName As String = "310UB040")
' DWGPath - path to dwg-file (w/o slash)
' DWGName - file name w/o extension
' There is no control for these parameters
Dim objLayer As AcadLayer, objBeam As Acad3DSolid, objRegEnt(0) As AcadEntity, objRegion As Variant
Dim objBlockRef As AcadBlockReference, objBlockExplode As Variant
Dim ptInsert As Variant, lCounter As Long
Dim file As String

file = DWGPath & "\" & DWGName & ".dwg"

  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.InsertBlock(ptInsert, _
      file, 1#, 1#, 1#, 0#)
  Else
    Set objBlockRef = ThisDrawing.ModelSpace.InsertBlock(ptInsert, _
      DWGName, 1#, 1#, 1#, 0#)
  End If
  objBlockExplode = objBlockRef.Explode
  objBlockRef.Delete
  For lCounter = LBound(objBlockExplode) To UBound(objBlockExplode)
    If objBlockExplode(lCounter).ObjectName = "AcDbPolyline" Then
      Set objRegEnt(0) = objBlockExplode(lCounter)
      objRegion = ThisDrawing.ModelSpace.AddRegion(objRegEnt)
      Exit For
    End If
  Next lCounter
  Set objBeam = ThisDrawing.ModelSpace.AddExtrudedSolid(objRegion(0), 1000#, 0)
  objRegion(0).Delete
  objRegEnt(0).Delete
  ThisDrawing.Regen acActiveViewport
End Function
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

CADaver

  • Guest
Re: extrude region from exploded block
« Reply #31 on: December 05, 2007, 07:42:22 PM »
I still find it odd you can extrude a closed pline in AotuCAD but not with VB...

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: extrude region from exploded block
« Reply #32 on: December 05, 2007, 07:55:17 PM »
I still find it odd you can extrude a closed pline in AotuCAD but not with VB...
Yup, it's even harder in arx, the thing is that a solid is made up of regions that are also 3d 'faces' that can have boolean operations performed on them for modeling, it must just be the way the acis engine works, but you're right in that they could have done it a lot easier with vba.
"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 #33 on: December 05, 2007, 07:56:49 PM »
Autocad commands frequently will wrap all the intricate details into a nice little package. When programming for it, though, you must quite often figure out how to get there using the Methods provided other objects.

Another, although not as difficult to work around, example is the AddAttribute method. It will add it with the current textstyle, but if that style has a Width factor set, the new attribute will not use that factor. The programmer must check the style's Width property for anything other than 1 and adjust the Attribute's ScaleFactor property accordingly. Adding an attribute in the Editor works as you'd expect.

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: extrude region from exploded block
« Reply #34 on: December 05, 2007, 10:37:18 PM »
Well that was fun! (NOT)
Half of my problem/s were the drg's are in 2006 format! I couldn't work out why once I hooked up the openfile dialog only the 310ub040 was working but I just realised I had opened and saved it in 2007 :roll:  :realmad:

Is there anyway around this issue??
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

Bryco

  • Water Moccasin
  • Posts: 1882
Re: extrude region from exploded block
« Reply #35 on: December 05, 2007, 11:09:56 PM »
Someone has posted this sub.
Code: [Select]
Public Function DrawingVersion(strFullPath As String) As String
    On Error Resume Next
  Dim i As Long
  Dim bytVersion(0 To 5) As Byte
  Dim strVersion As String
  Dim lngFile As Long
  If Len(dir(strFullPath)) > 0 Then
    lngFile = FreeFile
    Open strFullPath For Binary Access Read As lngFile
    Get #lngFile, , bytVersion
    Close lngFile
    strVersion = StrConv(bytVersion(), vbUnicode)
  End If
  If Len(strVersion) > 0 Then
    DrawingVersion = strVersion
  Else
    DrawingVersion = "NEWNEW"
  End If
End Function

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: extrude region from exploded block
« Reply #36 on: December 05, 2007, 11:33:17 PM »
Thanks Bryco,
so I'm to use this as an error handler of sorts to inform the user the file is the incorrect version only?

I'll do some more searching/research and I may write something to open, purge and save all of the files in the library, there's quite a few!
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Purge and Update folder drawings.
« Reply #37 on: December 06, 2007, 12:49:55 AM »
Here's something to open the files in a directory, purge them and save them as the current acad version, the code Bryco posted above could be used to make this more bullet proof I'd imagine.
Code: [Select]
Public Sub UpdatePurgeFiles(filepath As String)
Dim objAcad As AcadApplication

On Error GoTo Errhandler:
Set objAcad = AcadApplication
Dim sNextFile As String

sNextFile = Dir(filepath & "*.dwg")

While sNextFile <> ""
    objAcad.Documents.Open (filepath & sNextFile)
    objAcad.ActiveDocument.PurgeAll
    objAcad.ActiveDocument.Close True
    sNextFile = Dir
Wend

Exit Sub
Errhandler:
MsgBox "Error Updating and Purging Files!" & vbCrLf & _
        "Error Number: " & Err.Number
End Sub

an example -
Code: [Select]
Public Sub PandU()
Utils.UpdatePurgeFiles ("C:\DCS3d\BLUESCOPE SECTIONS_2007\EA\")
Utils.UpdatePurgeFiles ("C:\DCS3d\BLUESCOPE SECTIONS_2007\UA\")
Utils.UpdatePurgeFiles ("C:\DCS3d\BLUESCOPE SECTIONS_2007\PFC\")
Utils.UpdatePurgeFiles ("C:\DCS3d\BLUESCOPE SECTIONS_2007\UB\")
Utils.UpdatePurgeFiles ("C:\DCS3d\BLUESCOPE SECTIONS_2007\UC\")
End Sub

A bit rough and dirty but it worked :)
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

Bryco

  • Water Moccasin
  • Posts: 1882
Re: extrude region from exploded block
« Reply #38 on: December 06, 2007, 01:37:02 AM »
You may look at a couple of Jeff's posts using AxDbDocument to open a drawing behind the scenes, quicker.

In case you didn't know, you can open a cad drawing in notepad and the first line will tell you the version. (the rest is all gobbly gook)

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: extrude region from exploded block
« Reply #39 on: December 06, 2007, 02:51:40 AM »
Thanks Bryco, I will do when I get a bit further advanced in the app for sure.
I must admit, I'm having fun with this project, I haven't touched vb/a for years, now I have a better idea of how it works, what I want and need I'm making pretty speedy progress.

Thanks All for the help.
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien