liuhaixin88 Posted February 16, 2014 Share Posted February 16, 2014 Hello everyone,I need some help. Use LISP to insert dynamic block,But display:error: bad argument type: lentityp nil.I do not know how it is. Code is as follows: ;Modify the dynamic property values (defun DynamicProps (ename propname value / obj prpL cla cll prp) (vl-load-com) (setq obj (if (= (type ename) 'VLA-OBJECT) ename (vlax-ename->vla-object ename))) (if vla-getdynamicblockproperties (setq prpL (vlax-invoke obj 'getdynamicblockproperties))) (setq return (if (setq prp (vl-remove-if-not (function (lambda(x)(= (vlax-get-property x 'PropertyName) propname))) prpL)) (mapcar (function (lambda(v) (if (and (/= value nil)(vlax-property-available-p v 'Value)(/= (type value)'LIST)) (progn (vlax-put-property v 'Value value)(vla-update obj)) ) (if (and (vlax-property-available-p v 'AllowedValues) (vlax-get v 'AllowedValues)) (list (vlax-get v 'Value)(vlax-get v 'AllowedValues)) (vlax-get v 'Value) ) )) prp) (mapcar (function (lambda(v)(list (vla-get-propertyName v)(vlax-get v 'Value) v))) prpL) ) ) return ) ;=============================================================== ;Get polyline vertex (defun verpoytexs (ename / plist pp n) (setq obj (vlax-ename->vla-object ename)) (setq plist (vlax-safearray->list (vlax-variant-value (vla-get-coordinates obj)))) (setq n 0) (repeat (/ (length plist) 2) (setq pp (append pp (list (list (nth n plist)(nth (1+ n) plist))))) (setq n (+ n 2)) ) pp ) ;=============================================================== (defun c:tt ( / ss pt_copy pl_pt_lst off_real) (princ "\n Select the block to be processed:" ) (setq ss (ssget ":S" '((0 . "insert")))) (setq pt_copy (cdr (assoc 10 (entget (ssname ss 0))))) (or (= (vla-get-isdynamicblock (vlax-ename->vla-object e)):vlax-true) (exit)) (princ "\n Select polyline to be processed:" ) (setq pl_pt_lst (verpoytexs (ssname (ssget ":S" '((0 . "LWPOLYLINE"))) 0))) (setq off_real (getreal "\n Enter the interval width:")) (mapcar '(lambda (p1 p2) (vl-cmdf ".copy" ss "" "_none" pt_copy "_none" p1) (vl-cmdf ".rotate" (entlast) "" "_none" p1 "R" 0 p2) (DynamicProps (entlast) "L" (- (distance p1 p2) off_real)) ) pl_pt_lst (cdr pl_pt_lst) ) (princ) ) (vl-load-com) Insert dynamic block.dwg Quote Link to comment Share on other sites More sharing options...
pBe Posted February 16, 2014 Share Posted February 16, 2014 (edited) (defun c:tt ( / ss pt_copy pl_pt_lst off_real) (princ "\n Select the block to be processed:" ) [b] (if (and (setq ss (ssget ":S" '((0 . "insert")))) (or (= (vla-get-isdynamicblock (vlax-ename->vla-object [color="blue"](setq e (ssname ss 0))[/color])):vlax-true) (exit)) (princ "\n Select polyline to be processed:") (setq pl (ssget ":S" '((0 . "LWPOLYLINE")))) (setq off_real (getreal "\n Enter the interval width:")) )[/b] (progn (setq pt_copy (cdr (assoc 10 (entget [b][color="blue"]e[/color][/b])))) (setq pl_pt_lst (verpoytexs (ssname [b]pl[/b] 0))) (mapcar '(lambda (p1 p2) (vl-cmdf ".copy" ss "" "_none" pt_copy "_none" p1) (vl-cmdf ".rotate" (entlast) "" "_none" p1 "R" 0 p2) (DynamicProps (entlast) "L" (- (distance p1 p2) off_real)) ) pl_pt_lst (cdr pl_pt_lst) ) [b] ); progn ); if[/b] (princ) ) Edited February 17, 2014 by pBe Quote Link to comment Share on other sites More sharing options...
liuhaixin88 Posted February 16, 2014 Author Share Posted February 16, 2014 (defun c:tt ( / ss pt_copy pl_pt_lst off_real) (princ "\n Select the block to be processed:" ) [b] (if (and (setq ss (ssget ":S" '((0 . "insert")))) (or (= (vla-get-isdynamicblock (vlax-ename->vla-object e)):vlax-true) (exit)) (princ "\n Select polyline to be processed:") (setq pl (ssget ":S" '((0 . "LWPOLYLINE")))) (setq off_real (getreal "\n Enter the interval width:")) )[/b] (progn (setq pt_copy (cdr (assoc 10 (entget (setq e (ssname ss 0)))))) (setq pl_pt_lst (verpoytexs (ssname [b]pl[/b] 0))) (mapcar '(lambda (p1 p2) (vl-cmdf ".copy" ss "" "_none" pt_copy "_none" p1) (vl-cmdf ".rotate" (entlast) "" "_none" p1 "R" 0 p2) (DynamicProps (entlast) "L" (- (distance p1 p2) off_real)) ) pl_pt_lst (cdr pl_pt_lst) ) [b] ); progn ); if[/b] (princ) ) Thank you for your help. But problem still exists.When select the block, interrupt and display "error: bad argument type: lentityp nil." Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted February 16, 2014 Share Posted February 16, 2014 Change: (vlax-ename->vla-object e) to: (vlax-ename->vla-object (ssname ss 0)) Quote Link to comment Share on other sites More sharing options...
liuhaixin88 Posted February 16, 2014 Author Share Posted February 16, 2014 Change: (vlax-ename->vla-object e) to: (vlax-ename->vla-object (ssname ss 0)) Lee Mac,Now it's ok !Thank you! Quote Link to comment Share on other sites More sharing options...
pBe Posted February 17, 2014 Share Posted February 17, 2014 Change:... to: ..x Had it all mixed up. Thank you for catching the error LM Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted February 17, 2014 Share Posted February 17, 2014 Had it all mixed up. Thank you for catching the error LM No worries dude 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.