Author Topic: Explode during routine, select new objects  (Read 1639 times)

0 Members and 1 Guest are viewing this topic.

Dommy2Hotty

  • Swamp Rat
  • Posts: 1127
Explode during routine, select new objects
« on: July 29, 2004, 04:46:25 PM »
I wrote this routine to update our arrow block.  We used to use a routine that would have you draw two connected lines and insert an arrow block on the end for leader purposes.  I don't know if when my boss's started that there weren't leaders, but that's how I was shown how they do it.  I have since converted them to use leaders, but sometimes we work on older drawings and I like them to look nicer.  

ANYWAYS...what it does is inserts our new arrowhead and erases it, just to make the block part of the drawing and so that I can specify that as the leader arrowhead in dimstyle setup routine I'm working on.  Then, if the old arrow is in the drawing, it will re-insert the new arrowhead and re-define the old arrow block.  Problem with that is that now it's a block within a block.  How can I select the new arrowhead components (arcs and hatch) after I explode it?

Old arrowhead ~ Arrow2.dwg
New arrowhead ~ LeaderRC.dwg

Routine
Code: [Select]

;;***********************************************
;;               LeaderUpdate.lsp               *
;;          Created by Dominic Cesare           *
;;                 07.29.04                     *
;;***********************************************

;;**********************
;;*  Start of Routine  *
;;**********************


;define function
(defun c:LeaderUpdate (/ oldecho oldsnaps ent)
  (setq oldecho (getvar "cmdecho"))
  (setq oldsnaps (getvar "osmode"))
  (setvar "cmdecho" 0)
  (setvar "osmode" 0)

  ;;******************************
  ;;Insert "LeaderRC" block*******
  ;;******************************
  (if (tblsearch "block" "LeaderRC")
    (progn
      (command "-insert" "LeaderRC" "0,0" "" "" "")
      (setq ent (entlast))
      (command "erase" ent "")
      (prompt "\n***LeaderRC inserted successfully***")
      )
    (prompt "\n***LeaderRC already inserted***")
    )

  ;;******************************
  ;;Update current arrows*********
  ;;******************************
  (if (tblsearch "block" "Arrow2")
    (progn
      (command "-insert" "LeaderRC" "0,0" "" "" "180")
      (setq ent (entlast))
      (command "change" ent "" "p" "la" "0" "")
      (command "-block" "arrow2" "y" "0,0" ent "")
      (prompt "\n***Old arrow block updated***")
      )
    (prompt "\n***No older arrows to update***")
    )

;;********************************
;;Resetting changed variables*****
;;********************************
  (setvar "cmdecho" oldecho)
  (setvar "osmode" oldsnaps)
  (princ)
  )

;informs user how to run lisp
(prompt "\nType LeaderUpdate to run.....")
(princ)

;;**********************
;;*  End of Routine    *
;;**********************

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16717
  • Superior Stupidity at its best
Explode during routine, select new objects
« Reply #1 on: July 29, 2004, 10:54:35 PM »
Well, one trick is to grab the last entity in the drawing AFTER you insert the correct leader, then entnext until you have nil grabbing each successive entity and placing it in a selection set....

another is..

Code: [Select]

(command "-insert" "LeaderRC" "0,0" "" "" "180")
(setq ent (ssget "L"))
(command "explode" ent)
(setq ent (ssget "P"))
(command "change" ent "" "p" "la" "0" "")
(command "-block" "arrow2" "y" "0,0" ent "")


or something like that....

If you ssget the previous selection set that contained objects exploded by the explode command the previous selection set will contain ALL of the subentities in the exploded block.

To test this...
insert a block defined with multiple objects
explode the block
then do another command on the "previous" selection set...i.e.
Quote

Command: EXPLODE
Select objects: Specify opposite corner: 1 found
Select objects:
Command: MOVE
Select objects: P
3 found
Select objects:
Specify base point or displacement: Specify second point of displacement or
<use first point as displacement>:
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Dommy2Hotty

  • Swamp Rat
  • Posts: 1127
Explode during routine, select new objects
« Reply #2 on: July 29, 2004, 11:25:48 PM »
ahhh.....previous, not last....Thank you very much Keith, I'll test it out tomorrow....

b.t.w. ~ your avatars are freaking me out.... :yikes:

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16717
  • Superior Stupidity at its best
Explode during routine, select new objects
« Reply #3 on: July 29, 2004, 11:52:33 PM »
well good.... then I am doing my job.... :)
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Dommy2Hotty

  • Swamp Rat
  • Posts: 1127
Explode during routine, select new objects
« Reply #4 on: July 30, 2004, 11:23:16 AM »
Thanks Keith, works out perfectly...except I had the things to do after the tablesearch backwards...

Final Code:


Code: [Select]

;;***********************************************
;;               LeaderUpdate.lsp               *
;;          Created by Dominic Cesare           *
;;                 07.29.04                     *
;;***********************************************

;;**********************
;;*  Start of Routine  *
;;**********************


;define function
(defun c:LeaderUpdate (/ oldecho oldsnaps ent)
  (setq oldecho (getvar "cmdecho"))
  (setq oldsnaps (getvar "osmode"))
  (setvar "cmdecho" 0)
  (setvar "osmode" 0)

  ;;******************************
  ;;Insert "LeaderRC" block*******
  ;;******************************

  ;determine if LeaderRC is a current block in the drawing
  (if (tblsearch "block" "LeaderRC")
   
    ;if LeaderRC is already in the drawing
    (prompt "\n***LeaderRC already inserted***")

    ;if LeaderRC is NOT already in the drawing
    (progn
      (command "-insert" "LeaderRC" "0,0" "" "" "")
      (setq ent (entlast))
      (command "erase" ent "")
      (prompt "\n***LeaderRC inserted successfully***")
      )
    )

  ;;******************************
  ;;Update current arrows*********
  ;;******************************

  ;determine if Arrow2 is a current block in the drawing
  (if (tblsearch "block" "Arrow2")

    ;if Arrow2 is already in the drawing
    (progn
      (command "-insert" "LeaderRC" "0,0" "" "" "180")
      (setq ent (entlast))
      (command "explode" ent)
      (command "-block" "arrow2" "y" "0,0" "p" "")
      (prompt "\n***Old arrow block updated***")
      )

    ;if Arrow2 is NOT already in the drawing
    (prompt "\n***No older arrows to update***")
    )

;;********************************
;;Resetting changed variables*****
;;********************************
  (setvar "cmdecho" oldecho)
  (setvar "osmode" oldsnaps)
  (princ)
  )

;informs user how to run lisp
(prompt "\nType LeaderUpdate to run.....")
(princ)

;;**********************
;;*  End of Routine    *
;;**********************

Crank

  • Swamp Rat
  • Posts: 1439
Explode during routine, select new objects
« Reply #5 on: July 30, 2004, 12:57:06 PM »
You could replace
Code: [Select]

      (command "-insert" "LeaderRC" "0,0" "" "" "")
      (setq ent (entlast))
      (command "erase" ent "")

with just:
Code: [Select]

      (command "_.insert" "LeaderRC" (command))


Thinking about it... You can do the same for the whole routine:
Code: [Select]

;;**********************
;;*  Start of Routine  *
;;**********************

;define function
(defun c:LeaderUpdate (/ oldecho)
    (setq oldecho (getvar "CMDECHO")) (setvar "CMDECHO" 0)
    (if (tblsearch "BLOCK" "arrow2")
        (command "_.insert" "arrow2=LeaderRC" "y" (command))
    )

;;********************************
;;Resetting changed variables*****
;;********************************
  (setvar "CMDECHO" oldecho)
  (princ)
)

;informs user how to run lisp
(prompt "\nType LeaderUpdate to run.....")
(princ)

;;**********************
;;*  End of Routine    *
;;**********************

 Vault Professional 2018     /      Building Design Suite Ultimate 2017     /     AEC Collection 2018 + 2019 +2020