Jump to content

Recommended Posts

Posted (edited)

Hi all,

Can I add block to the polyline as attachment via lisp ?

I want to select all polyline then insert one block at selected polyline .

Thank for help.

block test.jpg

test add block.dwg

Edited by mostafa badran
add more details
Posted

you can use measue or devide command when asked to specify number type B and type the name of the block

Posted

mostafa,

 

First and foremost, you need to modify the insertion point of your block

to be at the tip of the arrow.

 

Second you may use the vlax-curve fuction to get the midpoint of your polylines.

 

(defun c:test ()
  (while  (setq ent (car (entsel "\nSelect polyline:")))
     (setq d (/ (vlax-curve-getDistAtParam ent (vlax-curve-getEndParam ent)) 2.0)
           p (vlax-curve-getPointAtDist ent d)
     )
     (vl-cmdf "._insert" "WIRE-TYPE" p "" "" "")
  )
)   

 

ymg

Posted
mostafa,

 

First and foremost, you need to modify the insertion point of your block

to be at the tip of the arrow.

 

Second you may use the vlax-curve fuction to get the midpoint of your polylines.

 

(defun c:test ()
  (while  (setq ent (car (entsel "\nSelect polyline:")))
     (setq d (/ (vlax-curve-getDistAtParam ent (vlax-curve-getEndParam ent)) 2.0)
           p (vlax-curve-getPointAtDist ent d)
     )
     (vl-cmdf "._insert" "WIRE-TYPE" p "" "" "")
  )
)   

ymg

Thanks ymg3 for respond, I do not know it is possible or not can you modify lisp to work with ssget function to insert block .

this thread maybe help .

http://www.cadtutor.net/forum/showthread.php?48143-LISP-to-find-midpoint-of-multiple-lines&p=327737&viewfull=1#post327737

Posted

(defun c:test (/ d e i p ss)
  (prompt "\nSelect polyline: ")
  (while  (setq ss (ssget '((0 . "LWPOLYLINE")(8 . "00-BT-PA-WIRE"))))
     (repeat (setq i (sslength ss))
        (setq e (ssname ss (setq i (1- i)))
              d (/ (vlax-curve-getDistAtParam e (vlax-curve-getEndParam e)) 2.0)
              p (vlax-curve-getPointAtDist e d)
        )
        (vl-cmdf "._insert" "WIRE-TYPE" p "" "" "")
     )
     (prompt "\nSelect polyline: ")
  )
  (princ)
)   

 

mostafa,

 

You are a senior member, I believe you could do it.

 

Do study the code and try to understand what is going on.

Posted
You are a senior member, I believe you could do it

 

Mostafa Autocad help is for just that if you looked up ssget under lisp and using selection filters you would have found the answer very quickly. Its part of ssget to understand how to make filter selections and these can be quite complicated. Type Layer Colour Linetype x value to mention a few.

Posted (edited)
(defun c:test (/ d e i p ss)
  (prompt "\nSelect polyline: ")
  (while  (setq ss (ssget '((0 . "LWPOLYLINE")(8 . "00-BT-PA-WIRE"))))
     (repeat (setq i (sslength ss))
        (setq e (ssname ss (setq i (1- i)))
              d (/ (vlax-curve-getDistAtParam e (vlax-curve-getEndParam e)) 2.0)
              p (vlax-curve-getPointAtDist e d)
        )
        (vl-cmdf "._insert" "WIRE-TYPE" p "" "" "")
     )
     (prompt "\nSelect polyline: ")
  )
  (princ)
)   

mostafa,

 

You are a senior member, I believe you could do it.

 

Do study the code and try to understand what is going on.

Thanks for your effort,

Thanks for your care to get me learn, I am really try to do it but I am field, then I ask you to do it to learn.

thanks again .:)

Edited by mostafa badran
font
Posted (edited)
Mostafa Autocad help is for just that if you looked up ssget under lisp and using selection filters you would have found the answer very quickly. Its part of ssget to understand how to make filter selections and these can be quite complicated. Type Layer Colour Linetype x value to mention a few.

Ok

BIGAL I know ssget quietly but the missing part is
 (setq e (ssname ss (setq i (1- i)))

I am really try to learn thank BIGAL for interest.:)

Edited by mostafa badran
code
Posted (edited)

To choose the point with point , you can use that too. It has the advantage that the block can sit where you want. It is not dependent on: the type of entity, layer, color, etc ,

 

 


(defun c:BlckIns ()
 (princ "\n   c:BlckIns  :   V  :  18 . 04 . 2014  ;")
 (setq osm (getVar "osMode")  )
 (setVar "osMode" 512)
 
  (while  (setq p (getPoint "\n  Select Point on Polyline :  < Enter = Stop > ;"))
;;;      (vl-cmdf "._insert" "WIRE-TYPE" p "" "" "")
     (command "_.Circle" p 200)
  )
 (setVar "osMode" osm)
 (princ "\n   c:BlckIns  :  END  ;")
 (princ)
)

Edited by Costinbos77
Posted

mostafa,

 

I know ssget quietly but the missing part is

 

At beginning of the repeat loop we are setting variable i to the length of the selection set (repeat (setq i (sslength ss))

 

Then inside the loop we read each ename that form the selection set, starting with the last one at index i minus 1.

The loop is decremented by 1 each time you go around.

 

Say your sslength was equal to 5. so you read ename (ssname ss 4)..3..2..1 ad finally 0.

 

ymg

Posted
mostafa,

 

 

 

At beginning of the repeat loop we are setting variable i to the length of the selection set (repeat (setq i (sslength ss))

 

Then inside the loop we read each ename that form the selection set, starting with the last one at index i minus 1.

The loop is decremented by 1 each time you go around.

 

Say your sslength was equal to 5. so you read ename (ssname ss 4)..3..2..1 ad finally 0.

 

ymg

thanks ymg3,

quite clear thank you so much.

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