Jump to content

Insert a line segment into a block


Ogopogo

Recommended Posts

Hi Fuccaro,

No worries as you must be busy with other requests. Your lisp works great, very much appreciated.

I do have another quest, base on the same block and line.

Is it possible, to click two end points and insert the length in the block?

I do apologizes, I should have asked this also at the beginning.

Link to comment
Share on other sites

That should not cause too many headaches:

 

(defun c:pp1( / bent sel enttype attr dist)
  (setq bent (car (entsel "select block")))
  (cond ((= (cdr (assoc 2 (entget bent))) "Wall-Tag-FW")
	 (while (/= (cdr (assoc 2 (entget bent))) "LENGTH-FT") (setq bent (entnext bent)))
	 (initget "Clicks")
	 (setq sel  (entsel "\nSelect (p)line or [Clicks]")
	       enttype (if (listp sel) (cdr (assoc 0 (setq line (entget (car sel)))))))
	 (cond
	   ((= enttype "LINE") (setq dist (distance (cdr (assoc 10 line)) (cdr (assoc 11 line)))))
	   ((= enttype "LWPOLYLINE") (setq dist (extract sel)))
	   ((= sel "Clicks") (setq dist (distance (setq p1 (getpoint "\n1st point")) (getpoint p1 "   2nd point"))))
	   )
	 (setq attr (entget bent)
	       attr (subst (cons 1 (rtos dist)) (assoc 1 attr) attr)
	       attr (entmod attr)))
	(T (princ "Wrong block!!!" ))
	)
  (princ)
  )
(defun extract(sel / p0 p1 p2 el found dist)
  (setq	p0 (osnap (cadr sel) "_nea")
	el (entget (car sel))
	el (if (= 1 (cdr (assoc 70 el))) (append el (list (assoc 10 el))) el)
	p1 nil p2 nil i -1 found nil)
  (while (and (not found) (< (setq i (1+ i)) (length el)))
    (cond ((= (car (nth i el)) 10) (setq p1 p2 p2 (cdr (nth i el)))))
    (setq found (and p1 (equal (setq dist (distance p1 p2)) (+ (distance p1 p0)(distance p0 p2)) 1e-5)))
    )
  (if found dist nil)  
  )

 

When the program prompts you to select the (p)line to get the length from,  press C -meaning you wish to enter the length by clicks- and... there you are! Use the Osnap to click End points, or Mid points or just click around in the model space at your heart's desire.

Link to comment
Share on other sites

Hi Fuccaro,

Thank you so much for creating these codes for me, it works marvellously. Having all my requests all in one file. Thank you for your time and your knowledge.

 

  • Like 1
Link to comment
Share on other sites

Hi Fuccaro,

I have another request but for a circle.

When you click on the inner circle it will insert the inside diameter and inside circumference both in feet-decimal into the "Wall-Rnd-Arc-Tag" block. Same for the outer circle, outside diameter and outside circumference in feet-decimal.

I have attached a Jpeg and Autocad files.

For the line / Pline request, it possible to insert the line length as a Feet-decimal? 

Thank you.

2 Circles.jpg

2 Circles.dwg

Link to comment
Share on other sites

I am familiar with metric units only. The lengths should be returned according to your local settings. So, how do you see now the text in the block attribute? it should be possible to make some calculations... I think

Link to comment
Share on other sites

My try:

(defun c:pp()
  (princ "\nCircles: ")
  (setq c2 (ssget))
  (setq r (mapcar '(lambda(x) (* 2 (cdr (assoc 40 (entget (ssname c2 x)))))) '(0 1)))
  (setq b (car (entsel "\nSelect block")))
  (while b
    (setq blist (entget b))
    (setq name (cdr (assoc 2 blist)))
    (cond
      ((= name "I.D.-FT") (putAttr blist (apply 'min r)))
      ((= name "I.C.-FT") (putAttr blist (* pi (apply 'min r))))
      ((= name "O.D.-FT") (putAttr blist (apply 'max r)))
      ((= name "O.C.-FT") (putAttr blist (* pi (apply 'max r))))
      )
    (setq b (entnext b))
    )
  )
(defun putAttr(att val)
   (entmod (subst (cons 1 (rtos val))(assoc 1 att) att))
  )

 

Link to comment
Share on other sites

Hi Fuccaro,

You're amazing! It works! Thank you very much for helping me on my request.

 

Fuccaro & Bigal

Regarding the Feet-Decimal, I have attached 2 screens shots.

The first screenshot is setting up the units in Primary and Alternate Units.

In the Primary Unit: selected "Decimal", selected "0.000", selected "Period",  typed in "apostrophe ( ' )" in the suffix and enter "1/12" in the scale factor.

In the Alternate Unit: selected "Architectural", precision "1/32" and multiplier "12".

The second screenshot shows both primary and alternate dimension. The first dimension is the "Feet-Decimal", the one I was asking about and wondering it is possible insert into the block.

2 Units.jpg

Feet-Deci.jpg

Link to comment
Share on other sites

Returning to the last lisp: there is no input check. It works fine if it is used right. At the first prompt select *exactly* two circles and at the second prompt give a block that has the desired attributes. It will put the desired texts in the block attributes . To change the units and/or the format - that will be your pleasure.

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