PDA

View Full Version : problem with exploding inserted blocks



jeans
22nd Jun 2005, 08:15 pm
After inserting a block I want to explode it, see the code below.
When running, the block does explode but the original is stil there...
...so I delete it at the end.

IS THIS THE RIGHT WAY ???

code:
InsPnt = ThisDrawing.Utility.GetPoint(, vbCrLf & "Insertionpoint:")
Set blockObj = ThisDrawing.ModelSpace.InsertBlock(InsPnt, BlockName, 1#, 1#, 1#, 0)

blockObj.Explode
blockObj.Update
blockObj.Delete

jeans
11th Jul 2005, 10:35 pm
no answers yet
is this such a strange question????

DANIEL
12th Jul 2005, 02:13 pm
i'm not sure i understand what your trying to do?

are you trying to automaticlly explode a block when you insert it with a lisp routine?

jeans
12th Jul 2005, 10:16 pm
after inserting a block i want to explode it. (all with vba)

without the code with 'blockObj.Delete', the block does explode but the original block and also the exploded entitys are there. I want only the exploded entitys ...so I delete the block at the end.

the program works but I wonder if this is the right way. If you explode a block in (standard) autocad, only the entitys are left.

the full code:

Private Sub cmdGo_Click()
Dim blockObj As AcadBlockReference
Dim insertionPnt(0 To 2) As Double
insertionPnt(0) = 0
insertionPnt(1) = 0
insertionPnt(2) = 0
Dim InsPnt As Variant

Dim gatdia As String
gatdia = cboDiameter.Value

Dim BlockName As String
If optContinuous.Value = True Then
BlockName = "Tapgat-" & gatdia & "-vaz.dwg"
If gatdia = "M2.5" Then BlockName = "Tapgat-M2-5-vaz.dwg"
Else
BlockName = "Tapgat-" & gatdia & "-vaz-hidden.dwg"
If gatdia = "M2.5" Then BlockName = "Tapgat-M2-5-vaz-hidden.dwg"
End If

Unload frm_schroefdraad_vaz
InsPnt = ThisDrawing.Utility.GetPoint(, vbCrLf & "Insertionpoint:")
Set blockObj = ThisDrawing.ModelSpace.InsertBlock(InsPnt, BlockName, 1#, 1#, 1#, 0)

blockObj.Explode
blockObj.Update
blockObj.Delete

End Sub

DANIEL
13th Jul 2005, 04:29 pm
if you use the insert command to insert a block you can select the "explode" option in the lower left corner of the dialog box to insert it exploded, is there any particular reason why you are wanting to do this through vba? I'm not much of a vba guy but i'm sure you could write a simple lisp routine to insert the blocks exploded with out going through the dialog box.

what version of autocad are you using?

jeans
13th Jul 2005, 06:22 pm
Thanks for answering me again!

Some people prefer lisp, some prefer vba. I understand vba better then lisp, although I wrote some (simple) lisp routines.

I'm not using the autocad dialog box. With the code first I open a dialogbox (made in vba) included a combobox. The user can select the block he wants and can place it anywhere in the drawing. That's all...

In the help file (autocad 2002):
"Inserting Exploded Blocks: Preceding the name of the block with an asterisk (*) explodes the block and inserts the individual parts of it. The block definition is not added to the drawing."

I'm not using the asterisk (*). How can I suppress it?



:D WHEN I HAVE A HELPFULL ANSWER THE SUN IS SHINING BRIGHTER THEN IT ALLREADY DOES :D

DANIEL
14th Jul 2005, 03:37 pm
you could put something like this in a if statement

(prompt
"\n<4> Explode block when inserted (auto EXPLODE) - ")
(prompt EXPLODE-SWITCH)

(progn
(initget 1 "1 2 3 4")
(setq EXPLODE-SWITCH
(getkword
"\nAuto EXPLODE (1=ASK-YES, 2=ASK-NO, 3=NO ASK-YES or 4=NO ASK-NO): "))
(if (= EXPLODE-SWITCH "1")
(setq EXPLODE-SWITCH "Ask-Default YES")
)
(if (= EXPLODE-SWITCH "2")
(setq EXPLODE-SWITCH "Ask-Default NO")
)
(if (= EXPLODE-SWITCH "3")
(setq EXPLODE-SWITCH "Do not Ask-Default YES")
)
(if (= EXPLODE-SWITCH "4")
(setq EXPLODE-SWITCH "Do not Ask-Default NO")
)
)
but thats not vba, might give you some ideas though :thumbsup:

Murph
14th Jul 2005, 05:29 pm
You could put two option buttons on your dialog, one for explode one for not exlode. When you run the your insertion sub then you will check which option button was selected and can always change


blknme= "*" & blknme
for when they want it exploded.

Good luck

jeans
14th Jul 2005, 08:00 pm
Murph,
the asterix "*" before the blockname results in "blockObj=nothing"

---------------------------------------------------------------------------
Daniel,
Thanks for the code, but that's not what I'm searching for...

------------------------------------------------------------------------

The code I wrote is working so maybe I think to difficult. But still I hope to find an answer soon... ...or later...


:lol: WHEN I HAVE A HELPFULL ANSWER THE SUN IS SHINING BRIGHTER THEN IT ALLREADY DOES :lol:

Murph
15th Jul 2005, 02:18 pm
I need to know what you will be doing after the block is inserted.

jeans
15th Jul 2005, 07:28 pm
I'm a die-designer. Our company makes tools for the production of sheet metal products. I make the design of the tools with Autocad.

To make the design drawing, I use i.a. standard parts, which I import and sometimes explode en sometimes not. I do nothing more with it.





:lol: WHEN I HAVE A HELPFULL ANSWER THE SUN IS SHINING BRIGHTER THEN IT ALLREADY DOES :lol:

Murph
15th Jul 2005, 11:32 pm
Try this.



Private Sub cmdGo_Click()
Dim blockObj As AcadBlockReference
Dim insertionPnt(0 To 2) As Double
insertionPnt(0) = 0
insertionPnt(1) = 0
insertionPnt(2) = 0
Dim InsPnt As Variant

Dim gatdia As String
gatdia = cboDiameter.Value

Dim BlockName As String
If optContinuous.Value = True Then
BlockName = "Tapgat-" & gatdia & "-vaz.dwg"
If gatdia = "M2.5" Then BlockName = "Tapgat-M2-5-vaz.dwg"
Else
BlockName = "Tapgat-" & gatdia & "-vaz-hidden.dwg"
If gatdia = "M2.5" Then BlockName = "Tapgat-M2-5-vaz-hidden.dwg"
End If

Unload frm_schroefdraad_vaz
InsPnt = ThisDrawing.Utility.GetPoint(, vbCrLf & "Insertionpoint:")
If OptionButton1.Value = 1 Then
Blockname = "*" & Blockname
End If
Set blockObj = ThisDrawing.ModelSpace.InsertBlock(InsPnt, BlockName, 1#, 1#, 1#, 0)


End Sub

SpeedCAD
15th Jul 2005, 11:55 pm
Hi...

When you explode a block you get a matriz with its objects. But the block you must delete after. Is the same with vla-explode function from Visual Lisp... You are right...

Why don't you want delete the block????

jeans
16th Jul 2005, 08:46 am
Murph,

I allready tried it, but error: objblock=nothing (see above)
So it doesn't work...
----------------------------------------------------------------------------------

Speedcad,
I want to delete the block because then I have double entitys: the block and the exploded entitys on it. When I explode the block, I don't want the block anymore...




:lol: WHEN I HAVE A HELPFULL ANSWER THE SUN IS SHINING BRIGHTER THEN IT ALLREADY DOES :lol:

Murph
16th Jul 2005, 01:49 pm
after inserting a block i want to explode it. (all with vba)

without the code with 'blockObj.Delete', the block does explode but the original block and also the exploded entitys are there. I want only the exploded entitys ...so I delete the block at the end.

the program works but I wonder if this is the right way. If you explode a block in (standard) autocad, only the entitys are left.


This is correct. With VBA you will have the block left along with the exploded entitys. You will have to delete the block after exploding. Just put an If...Then statement in front of it so you can use it for all insertions and just have it explode only those blocks you have elected to.

jeans
21st Jul 2005, 05:42 pm
Thanks a lot for all answers !!!