Jump to content

Finding a blocks insertion point and inserting a another block in the same spot.


Recommended Posts

Posted (edited)

Hello i need a lisp rutine that could find a Blocks (Drawing Head) insertion point and a insert another block in the same spot. I don't presume that could be a long lisp rutine. I have looked around on the internet. I have also seen a recent lisp rutine were the the user have to pick the block to Rotate a Block at a angle that the user pick or give. I need some think that could find the blocks insert point just by looking for the block name and insert another block in the same insertion point of the first block.

 

Thx i advance. :D

Edited by elfert
  • Replies 22
  • Created
  • Last Reply

Top Posters In This Topic

  • elfert

    11

  • BlackBox

    5

  • stevesfr

    2

  • jpcadconsulting

    2

Posted

Look up help for SSGET it allows "Filters" basicly use a filter for search all blocks and return a block named xyz

 

Do (setq ans (entsel)) select your block then (entget (car ans)) you will now see all the dxf codes as they are known you need to use (0 . "INSERT") and (2 . "your blockname") maybe also (410 . "Layout1") current layout, hint try also "Model". The insertion point is (10 0.0 0.0 0.0) in my block picked,

 

(setq ans (entsel))
(setq en (entget (car ans)))
(setq inspt (cdr (assoc 10 en)))
(princ inspt)
; (car inspt) is X
; (cadr inspt) is Y
;(caddr inspt) is Z

;(ssget "X"  (0 . "INSERT")(2 . "your blockname"))
;warning if more than once will return all

Posted (edited)
Look up help for SSGET it allows "Filters" basicly use a filter for search all blocks and return a block named xyz

 

Do (setq ans (entsel)) select your block then (entget (car ans)) you will now see all the dxf codes as they are known you need to use (0 . "INSERT") and (2 . "your blockname") maybe also (410 . "Layout1") current layout, hint try also "Model". The insertion point is (10 0.0 0.0 0.0) in my block picked,

 

(setq ans (entsel))
(setq en (entget (car ans)))
(setq inspt (cdr (assoc 10 en)))
(princ inspt)
; (car inspt) is X
; (cadr inspt) is Y
;(caddr inspt) is Z

;(ssget "X"  (0 . "INSERT")(2 . "your blockname"))
;warning if more than once will return all

 

 

I this program i need to select a block and it returns a insertion point. What i am searching for is a rutine that finds a block based on a specific block name and finds this blocks insertion point this insertion point it have to use to insert another block not the same block as the first one.

I have read the SSGET at jefferypsanders.com and also about filter but what i understand i have to use a SSGET "X" and filter out the block name but how is that possible when the only name that it can filter out is layer name. ?

 

I have about 3 kilos of drawings that i have a put a 'AS built' sign on thats why i am asking and hoping that i could use the rutine in a script batch.

 

Thank you in advance.

 

elfert

Edited by elfert
Mis leading
Posted
I this program i need to select a block and it returns a insertion point. What i am searching for is a rutine that finds a block based on a specific block name and finds this blocks insertion point this insertion point it have to use to insert another block not the same block as the first one.

I have read the SSGET at jefferypsanders.com and also about filter but what i understand i have to use a SSGET "X" and filter out the block name but how is that possible when the only name that it can filter out is layer name. ?

 

I have about 3 kilos of drawings that i have a put a 'AS built' sign on thats why i am asking and hoping that i could use the rutine in a script batch.

 

Thank you in advance.

 

elfert

 

I look a little around afralisp and found may be a solution to my problem, but i can't get it to function probably can some one help.

 

(defun c:asbuilt2 ( / p1 b a en inspt )

(setq p1 (getstring "\Name of Block : "))

((setq b (cons 2 p1)))

(setq a (ssget "x" (list b)))

(setq en (entget (car a)))

(setq inspt (cdr (assoc 10 en)))

(princ inspt)

)

I am trying to make the program return the insertion point of the name of the block that i tell it. But i get a error

; error: bad function: (2 . "dwg"). ; dwg is my test block name.

 

Any help appreciate...thx in advance....from a person how makes mistakes...elfert!

Posted

If there is only one instance of the block in the drawing, this will give you its insertion point:

 

(defun c:asbuilt2 (/ a b c)
 (setq	a (ssget "_X" '((0 . "INSERT") (2 . "block-name")))
b (sslength a)
 )

 (repeat b
   (setq b (1- b)
  c (append c (cdr (assoc 10 (entget (ssname a b)))))
   )
 )
 (princ c)
 (princ)
)

 

If there is more than one, it'll list all insertion points.

Posted
If there is only one instance of the block in the drawing, this will give you its insertion point:

 

(defun c:asbuilt2 (/ a b c)
 (setq    a (ssget "_X" '((0 . "INSERT") (2 . "block-name")))
   b (sslength a)
 )

 (repeat b
   (setq b (1- b)
     c (append c (cdr (assoc 10 (entget (ssname a b)))))
   )
 )
 (princ c)
 (princ)
)

If there is more than one, it'll list all insertion points.

 

Thx that did it. i have finish the program. thank you very much. I will try to fine tune it and then publish it later.

  • 2 weeks later...
Posted
;Inserts a 'ASBUILT' sign in the selected block insertion point.call commando with asbuilt1
(Defun C:Asbuilt1 ( / ans en inspt)
(setq ans (entsel))
(setq en (entget (car ans)))
(setq inspt (cdr (assoc 10 en)))
(Command "-insert" "ASBUILT" inspt "" "" "" )
)
;inserts a 'ASBUILT' sign in the same spot as the block Drawinghead. call commando with asbuilt2
(defun c:asbuilt2 (/ a b c)
 (setq    a (ssget "_X" '((0 . "INSERT") (2 . "Drawinghead")))
   b (sslength a)
 )
 (repeat b
   (setq b (1- b)
     c (append c (cdr (assoc 10 (entget (ssname a b)))))
   )
 )
 (command "insunits" "4" "")
 (Command "-insert" "ASBUILT" c "" "" "" )
 (princ)
)

Here you go! Still a Novice Lisp programmer......:ouch:

Posted

Elfert,

 

Be sure to consider the possibility of ANS = nil (in C:Asbuilt1), or A = nil (in c:asbuilt2). ;)

 

Perhaps an IF statement would help you to mitigate potential errors - Example:

 

(defun c:[color=red]FOO[/color]  (/ ss)
 (if (and (setq ss (ssget ":S:E" '((0 . "INSERT"))))
          (findfile "ASBUILT.dwg"))
   (command "._-insert"
            "ASBUILT"
            (cdr (assoc 10 (entget (ssname ss 0))))
            1.0
            1.0
            0.0)
   (cond (ss (prompt "\n** \"ASBUILT.dwg\" cannot be found ** "))
         ((prompt "\n** Nothing selected ** "))))
 (princ))

 

** Edit to add - I personally try to explicitly define the scale, and rotation when inserting a block to avoid potential errors there also.

 

HTH

Posted

Thx. Renderman i will look into it. I will try to publish a new code to consider, asap. :thumbsup:

Posted

You're welcome... I'm glad you found my post to be useful. :)

Posted

Hello Renderman,8) I am still a Novice Lisp programmer :cry: so is it possible for you to do some ;; explanation ? Some of the code is understandable but not all. I the mean time i will try to look at Afra lisp. For explanation.

Posted
Hello Renderman,8) I am still a Novice Lisp programmer :cry: so is it possible for you to do some ;; explanation ? Some of the code is understandable but not all. I the mean time i will try to look at Afra lisp. For explanation.

 

No worries; we all start somewhere. ;)

 

I encourage you to read anything an everything you can. You will learn a lot from common resources like the Developer Documentation, CAD Forums like this, and others who've been kind enough to share their wisdom through tutorials hosted on their website(s). One book that I found to be very easy to read, and understand, was David M. Stein's The Visual LISP Developer's Bible, 2011 Edition which is now on sale for $6.99 (image is linked):

 

vldb_cover_2011.JPG?height=320&width=244

 

As for some explanation, hopefully this will help:

 

(defun c:FOO  (/ ss)
[color=seagreen]
 ;; Both test expressions within the AND function must 
 ;; return a non-nil value.
 ;;
 ;; If the user makes a valid, single selection of a block,
 ;; and the block "Asbuilt.dwg" can be found for insert...[/color]
 (if (and (setq ss (ssget ":S:E" '((0 . "INSERT"))))
          (findfile "ASBUILT.dwg"))

  [color=seagreen] ;; ... Then, insert the "Asbuilt" block at the insertion
   ;; point of the earlier selected block[/color]
   (command "._-insert"
            "ASBUILT"
            (cdr (assoc 10 (entget (ssname ss 0))))
            1.0
            1.0
            0.0)

   [color=seagreen];; ... Else, CONDitionally report to the user what
   ;; went wrong above, based on the first test expression
   ;; that returns a non-nil value.
   ;;
   ;; First condition:
   ;; If a valid, single selection was made, then
   ;; the "Asbuilt" block could not be found.
   ;;
   ;; Second condition:
   ;; A valid, single selection was NOT made.[/color]
   (cond (ss (prompt "\n** \"ASBUILT.dwg\" cannot be found ** "))
         ((prompt "\n** Nothing selected ** "))))
 (princ))

Posted

Is it possible to get the book as a book not kindle? I don't own a kindle :cry:

Posted
;Inserts a 'ASBUILT' sign in the selected block insertion point.call commando with asbuilt1
(Defun C:Asbuilt1 ( / ans en inspt)
(setq ans (entsel))
(setq en (entget (car ans)))
(setq inspt (cdr (assoc 10 en)))
(Command "-insert" "ASBUILT" inspt "" "" "" )
)
;inserts a 'ASBUILT' sign in the same spot as the block Drawinghead. call commando with asbuilt2
(defun c:asbuilt2 (/ a b c)
 (setq    a (ssget "_X" '((0 . "INSERT") (2 . "Drawinghead")))
   b (sslength a)
 )
 (repeat b
   (setq b (1- b)
     c (append c (cdr (assoc 10 (entget (ssname a b)))))
   )
 )
 (command "insunits" "4" "")
 (Command "-insert" "ASBUILT" c "" "" "" )
 (princ)
)

Here you go! Still a Novice Lisp programmer......:ouch:

 

program sort of works, what can we add to erase the existing Drawinghead block ? after the insertion of Asbuilt block. at the moment I end up with both blocks at the initial insertion point (that of Drawinghead block)

TIA

Steve

Posted

Why erase the drawing head?

 

The problem i my situation was that i had 3 kilos of drawings that i need to put a As build sign on. So a great help from the forum members i got this routine to work. The drawing head was on the drawings so i just need to make a block that would be inserted every time i called the command. So i made a block were i wanted it to be on the drawing used the same insertion point as the drawing head save the block in a folder that AC would know of i could then use a script on the drawings that need the sign.

Posted
Why erase the drawing head?

 

The problem i my situation was that i had 3 kilos of drawings that i need to put a As build sign on. So a great help from the forum members i got this routine to work. The drawing head was on the drawings so i just need to make a block that would be inserted every time i called the command. So i made a block were i wanted it to be on the drawing used the same insertion point as the drawing head save the block in a folder that AC would know of i could then use a script on the drawings that need the sign.

 

This was my purpose for adapting this program. If the initial release of the drawings were "For Bid Only" and then they progressed to "Approved For Construction" then finally to "AsBuilt" or "AsConstructed", then each issue would have the appropriate block and a program could be adapted in order to progress from one text block to another as the project progressed from one stage to another. For example, the "For Bid Only" block could quickly be replaced with the "Approved For Construction" etc. with the old block automatically deleted. Now you know the rest of the story.

Help appreciated for erasing the existing block when the updated one is inserted.

TIA, Steve

Posted (edited)

I think in you situation its possible to make a Attribute tag inside of you drawing head that specify the current state of the drawing progress. Then you should consider a routine that could read the tag and change depending on what state the drawing is in. You could also make one block with the attribute inside that the routine looks inside a do the same check of state. But be aware of to make it easy for the user to use and really plan this steps carefully with the the novice user in mind. But i would say that i am still a novice lisp programmer and in a learning phase so i can't from one minute to another give you a routine sorry about that.

Edited by elfert
Mis guiding
Posted

FWIW - The "issue" description is incorporated into our title blocks as an a FIELD populated attribute that reads a custom property of our project's Sheet Set Manager (SSM) file. That way, when the submittal issue changes as described above, we change the value once in SSM, and plot the plan set. Walla - all sheets have been updated.

 

Separately, to answer the question of deleting the original block... One way is to simply pass the entity name to the erase command after inserting the replacement block, or at minimum after you've extracted the insertion point of the. Lock to be deleted:

 

(command "._erase" <entityName> "")

Posted
Is it possible to get the book as a book not kindle? I don't own a kindle :cry:

 

Unfortunately the answer is no.

 

I've actually read the book on my smartphone using free Kindle App, or online.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...