Jump to content

block place near of the end of line


Guest cad2007

Recommended Posts

You can save some headache by just entmod'ing the insertion point instead of deleting and recreating.

 

That's of course much better .

 

So I've been trying to replace the end point of the selected line to be the Block insertion point , but without a pass .

 

Check this out please ....

(defun c:THib (/ ss start e ent answer)
 (if (setq ss (car (entsel "\n Select Line :")))
   (progn
     (setq start (cdr (assoc 10 (setq e (entget ss)))))
       (setq ent (entmakex (list (cons 0 "INSERT")(cons 2 "ss")(cons 10 start)(cons 50 0))))
           (initget "Yes No")
              (setq answer (getkword "\n Agree with this side [Yes/No] :"))
                 (if (eq answer "No")
                    [color="red"](entmod (subst (cons 11 e) (assoc 10 ent) ent))[/color]
                  (princ)))
         (princ)
      ))

Link to comment
Share on other sites

  • Replies 29
  • Created
  • Last Reply

Top Posters In This Topic

  • alanjt

    9

  • Tharwat

    7

  • mdbdesign

    5

Top Posters In This Topic

Posted Images

That's of course much better .

 

So I've been trying to replace the end point of the selected line to be the Block insertion point , but without a pass .

 

Check this out please ....

(defun c:THib (/ ss start e ent answer)
 (if (setq ss (car (entsel "\n Select Line :")))
   (progn
     (setq start (cdr (assoc 10 (setq e (entget ss)))))
       (setq ent (entmakex (list (cons 0 "INSERT")(cons 2 "ss")(cons 10 start)(cons 50 0))))
           (initget "Yes No")
              (setq answer (getkword "\n Agree with this side [Yes/No] :"))
                 (if (eq answer "No")
                    [color="red"](entmod (subst (cons 11 e) (assoc 10 ent) ent))[/color]
                  (princ)))
         (princ)
      ))

(cons 10 e) instead of (cons 11 e)
Link to comment
Share on other sites

Still does not work with entmod function .
You are trying to entmod an entity, not the entity's data.

Here's a little cleaner option:

(defun c:Test (/ e b)
 (and
   (setq e (car (entsel "\nSelect line: ")))
   (setq b (entget (entmakex (list '(0 . "INSERT") (cons 2 "P6") (assoc 10 (entget e))))))
   (eq "Yes" (progn (initget 0 "Yes No") (getkword "\nSwap end points? [Yes/No] <No>: ")))
   (entmod (subst (cons 10 (cdr (assoc 11 (entget e)))) (assoc 10 b) b))
 )
 (princ)
)

 

Change to block to whatever, I just typed the first block name I could think of.

Link to comment
Share on other sites

Wonderful Alanjt.

 

The way you added the *entget* before *entmakex* is really very smart which would give us the control of the entity that just have inserted.

 

So here are the codes after the correction .

 

(defun c:THib (/ ss1 ent e answer)
 (if (setq ss1 (car (entsel "\n Select Line :")))
       (setq ent (entget (entmakex (list (cons 0 "INSERT")(cons 2 "ss")
			 (cons 10 (cdr (assoc 10 (setq e (entget ss1)))))
			 ))))     
                 (princ)
          )
           (initget "Yes No")
              (setq answer (getkword "\n Agree with this side [Yes/No] :"))
                 (if (eq answer "No")
                    (entmod (subst (cons 10 (cdr (assoc 11 e))) (assoc 10 ent) ent))
                  (princ))
         (princ)
      )

 

 

Thank you so much Alanjt for your help and clarification as well.

Link to comment
Share on other sites

Wonderful Alanjt.

 

The way you added the *entget* before *entmakex* is really very smart which would give us the control of the entity that just have inserted.

 

So here are the codes after the correction .

 

(defun c:THib (/ ss1 ent e answer)
 (if (setq ss1 (car (entsel "\n Select Line :")))
       (setq ent (entget (entmakex (list (cons 0 "INSERT")(cons 2 "ss")
			 (cons 10 (cdr (assoc 10 (setq e (entget ss1)))))
			 ))))     
                 (princ)
          )
           (initget "Yes No")
              (setq answer (getkword "\n Agree with this side [Yes/No] :"))
                 (if (eq answer "No")
                    (entmod (subst (cons 10 (cdr (assoc 11 e))) (assoc 10 ent) ent))
                  (princ))
         (princ)
      )

 

 

Thank you so much Alanjt for your help and clarification as well.

You should really study my code. You could save yourself some legwork.
Link to comment
Share on other sites

You should really study my code. You could save yourself some legwork.

 

I do appreciate your point of view, and your way of coding is really very rare and genious, undoubtly.

 

I tried to constuct the codes as the way you made it ....

 

(defun c:THib (/ ss1 ent e)
 (and (setq ss1 (car (entsel "\n Select Line :")))
      (setq ent (entget (entmakex (list (cons 0 "INSERT")(cons 2 "ss") 
                               (cons 10 (cdr (assoc 10 (setq e (entget ss1)))))))))                
      (eq "No" (progn (initget 0 "No Yes")(getkword "\n Agree with this side [Yes/No] <Yes>:")))
      (entmod (subst (cons 10 (cdr (assoc 11 e))) (assoc 10 ent) ent)))
    (princ)
 )

 

Many thanks.

Link to comment
Share on other sites

I do appreciate your point of view, and your way of coding is really very rare and genious, undoubtly.

 

I tried to constuct the codes as the way you made it ....

 

(defun c:THib (/ ss1 ent e)
 (and (setq ss1 (car (entsel "\n Select Line :")))
      (setq ent (entget (entmakex (list (cons 0 "INSERT")(cons 2 "ss") 
                               (cons 10 (cdr (assoc 10 (setq e (entget ss1)))))))))                
      (eq "No" (progn (initget 0 "No Yes")(getkword "\n Agree with this side [Yes/No] <Yes>:")))
      (entmod (subst (cons 10 (cdr (assoc 11 e))) (assoc 10 ent) ent)))
    (princ)
 )

Many thanks.

All you did was copy my code and change prompts. I want to make sure you understand why I did what I did, not just do what I did.

 

The code is far from perfect, it can easily fail if the block is unable to be created or the object selected is not a line. I would def. check to make sure the block exists and the object is a line.

 

Try and see if you can figure out how to make it work from the first piece of code I posted (automatically derive the closest end point. Hint: Use the point returned from (entsel) as your comparison point for closeness.

Link to comment
Share on other sites

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...