mostafa badran Posted April 17, 2014 Share Posted April 17, 2014 (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. test add block.dwg Edited April 17, 2014 by mostafa badran add more details Quote Link to comment Share on other sites More sharing options...
samifox Posted April 17, 2014 Share Posted April 17, 2014 you can use measue or devide command when asked to specify number type B and type the name of the block Quote Link to comment Share on other sites More sharing options...
ymg3 Posted April 17, 2014 Share Posted April 17, 2014 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 Quote Link to comment Share on other sites More sharing options...
mostafa badran Posted April 17, 2014 Author Share Posted April 17, 2014 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 Quote Link to comment Share on other sites More sharing options...
ymg3 Posted April 17, 2014 Share Posted April 17, 2014 (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. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted April 18, 2014 Share Posted April 18, 2014 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. Quote Link to comment Share on other sites More sharing options...
mostafa badran Posted April 18, 2014 Author Share Posted April 18, 2014 (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 April 18, 2014 by mostafa badran font Quote Link to comment Share on other sites More sharing options...
mostafa badran Posted April 18, 2014 Author Share Posted April 18, 2014 (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 April 18, 2014 by mostafa badran code Quote Link to comment Share on other sites More sharing options...
Costinbos77 Posted April 18, 2014 Share Posted April 18, 2014 (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 April 18, 2014 by Costinbos77 Quote Link to comment Share on other sites More sharing options...
ymg3 Posted April 18, 2014 Share Posted April 18, 2014 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 Quote Link to comment Share on other sites More sharing options...
mostafa badran Posted April 18, 2014 Author Share Posted April 18, 2014 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.