jan_ek Posted October 25, 2019 Posted October 25, 2019 (edited) Hello, how to get coordinates of a polyline on a layer eg "Boundary" inside a block . I would like the coordinates to be in the global system. I found some code but it returns coordinates relative to the base point of the block https://forums.augi.com/showthread.php?83935-Creating-a-list-Polyline-vertices Edited October 25, 2019 by jan_ek Quote
BIGAL Posted October 25, 2019 Posted October 25, 2019 If you can get the co-ords and the insbase point of the block, then current insertion point you can work out a offset to add to the vertices. Quote
Tharwat Posted October 26, 2019 Posted October 26, 2019 You can use the command: NCOPY then retrieve the coordinate of the derived polyline from the block. Quote
jan_ek Posted October 26, 2019 Author Posted October 26, 2019 Unfortunately, the AutoCad substitute does not have this function "Unable to recognize command "NCOPY". This error can occur when the command is not supported for the active license." Quote
Tharwat Posted October 26, 2019 Posted October 26, 2019 The NCOPY command is included with the Express Tools and apparently you don't have them installed with your AutoCAD version. Quote
jan_ek Posted October 26, 2019 Author Posted October 26, 2019 Sorry I didn't write at first, I use bricscad Quote
Tharwat Posted October 26, 2019 Posted October 26, 2019 The following routine should print the coordinates of all polylines that on layer "Boundary" in the selected block to the command line. NOTE: Be sure to have all your layers unlocked. (defun c:Test (/ sel lst pts) ;; Tharwat - 26.Oct.2019 ;; (and (setq sel (car (entsel "\nSelect a Block :"))) (or (= (cdr (assoc 0 (entget sel))) "INSERT") (alert "Selected object is not a block <!>") ) (setq lst (vlax-invoke (vlax-ename->vla-object sel) 'Explode)) (mapcar '(lambda (obj) (and (= (vla-get-objectname obj) "AcDbPolyline") (= (vla-get-layer obj) "Boundary") (setq pts (cons (mapcar 'cdr (vl-remove-if-not '(lambda (p) (= (car p) 10)) (entget (vlax-vla-object->ename obj)) ) ) pts ) ) ) ) lst ) (mapcar 'vla-delete lst) ) (if pts (princ pts) (princ) ) ) (vl-load-com) Quote
Lee Mac Posted October 26, 2019 Posted October 26, 2019 (edited) For what it's worth, it is not necessary to perform a nested copy of the polyline, nor explode the block reference in order to ascertain the polyline vertex coordinates with respect to the block reference - instead, you can transform the polyline vertices obtained from the block definition using the position, scale, rotation & orientation of the block reference. This is a very similar question to that posed in this thread. To offer an example, consider the following code: (defun c:test ( / ent enx lst ocs ) (while (progn (setvar 'errno 0) (setq ent (car (entsel "\nSelect block: "))) (cond ( (= 7 (getvar 'errno)) (princ "\nMissed, try again.") ) ( (null ent) nil ) ( (/= "INSERT" (cdr (assoc 0 (setq enx (entget ent))))) (princ "\nThe selected object is not a block.") ) ( (null (setq lst (blockreferencepolylinevertices ent))) (princ "\nThe selected block does not contain a 2D polyline on the Boundary layer.") ) ( (progn (setq ocs (cdr (assoc 210 enx))) (entmake (append (list '(000 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline") (cons 090 (length lst)) '(070 . 0) (cons 038 (cadddr (assoc 010 enx))) (cons 210 ocs) ) (mapcar '(lambda ( p ) (cons 10 (trans p 0 ocs))) lst) ) ) ) nil ) ( (princ "\nUnable to recreated nested polyline.")) ) ) ) (princ) ) (defun blockreferencepolylinevertices ( ref / elv ent enx lst ocs ) (setq ent (tblobjname "block" (cdr (assoc 2 (entget ref))))) (while (and (null lst) (setq ent (entnext ent)) (setq enx (entget ent)) ) (if (and (= "LWPOLYLINE" (cdr (assoc 0 enx))) (= "BOUNDARY" (strcase (cdr (assoc 8 enx)))) ) (setq elv (cdr (assoc 038 enx)) ocs (cdr (assoc 210 enx)) lst (mapcar '(lambda ( v ) (trans (list (cadr v) (caddr v) elv) ocs 0) ) (vl-remove-if-not '(lambda ( x ) (= 10 (car x))) enx) ) ) ) ) (if lst (apply (function (lambda ( mat vec ) (mapcar (function (lambda ( vtx ) (mapcar '+ (mxv mat vtx) vec) ) ) lst ) ) ) (refgeom ref) ) ) ) ;; RefGeom (gile) ;; Returns a list whose first item is a 3x3 transformation matrix and ;; second item the object insertion point in its parent (xref, block or space) (defun refgeom ( ent / ang enx mat ocs ) (setq enx (entget ent) ang (cdr (assoc 050 enx)) ocs (cdr (assoc 210 enx)) ) (list (setq mat (mxm (mapcar '(lambda ( v ) (trans v 0 ocs t)) '( (1.0 0.0 0.0) (0.0 1.0 0.0) (0.0 0.0 1.0) ) ) (mxm (list (list (cos ang) (- (sin ang)) 0.0) (list (sin ang) (cos ang) 0.0) '(0.0 0.0 1.0) ) (list (list (cdr (assoc 41 enx)) 0.0 0.0) (list 0.0 (cdr (assoc 42 enx)) 0.0) (list 0.0 0.0 (cdr (assoc 43 enx))) ) ) ) ) (mapcar '- (trans (cdr (assoc 10 enx)) ocs 0) (mxv mat (cdr (assoc 10 (tblsearch "block" (cdr (assoc 2 enx)))))) ) ) ) ;; Matrix Transpose - Doug Wilson ;; Args: m - nxn matrix (defun trp ( m ) (apply 'mapcar (cons 'list m)) ) ;; Matrix x Matrix - Vladimir Nesterovsky ;; Args: m,n - nxn matrices (defun mxm ( m n ) ((lambda ( a ) (mapcar '(lambda ( r ) (mxv a r)) m)) (trp n)) ) ;; Matrix x Vector - Vladimir Nesterovsky ;; Args: m - nxn matrix, v - vector in R^n (defun mxv ( m v ) (mapcar '(lambda ( r ) (apply '+ (mapcar '* r v))) m) ) (princ) Edited October 26, 2019 by Lee Mac 1 Quote
Wan Posted October 17, 2023 Posted October 17, 2023 Hi Mr. Lee, Thank you for the above code. Is there any code to create layers for these blocks automatically just after I created them? Quote
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.