muck Posted June 21, 2009 Share Posted June 21, 2009 AutoCAD 2009 & 10 VBA. Is it possable to pick a specific exploded entity to get it's layer name? Can a person take this one step farther and pick a specifc enitity in a block? I would like to know how to do this in both cases if possable. Thank you, Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 21, 2009 Share Posted June 21, 2009 Does it have to be VBA... Quote Link to comment Share on other sites More sharing options...
SEANT Posted June 21, 2009 Share Posted June 21, 2009 A VBA version would be something like this: Sub GetNestedEnt() Dim varPckPt As Variant Dim obj As AcadObject Dim varMatrix As Variant Dim lngContext As Long Dim strObjName As String Dim strText As String Dim ent As AcadEntity On Error GoTo MissedPick ThisDrawing.Utility.GetSubEntity obj, varPckPt, varMatrix, lngContext, "Select an entity: " Set ent = obj MsgBox ent.Layer On Error GoTo 0 Exit Sub MissedPick: MsgBox "Missed Pick!" End Sub Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 21, 2009 Share Posted June 21, 2009 LISP is much more concise... (defun c:getlay (/ ent) (and (setq ent (car (nentsel "\nSelect Entity: "))) (princ (strcat "\nLayer is: " (cdr (assoc 8 (entget ent)))))) (princ)) Quote Link to comment Share on other sites More sharing options...
SEANT Posted June 21, 2009 Share Posted June 21, 2009 LISP is much more concise... It always is. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 21, 2009 Share Posted June 21, 2009 Are you going to learn LISP Sean or move straight into the .NET's or C#/++? Or do you already know LISP, but use VBA instead? As I have found with 2010, VBA is no longer here... Quote Link to comment Share on other sites More sharing options...
SEANT Posted June 21, 2009 Share Posted June 21, 2009 There was a rather particular set of circumstances that had me bypass AutoLisp in favor of VBA (mostly due to VB based support in other often used applications). I really wish I had devoted the necessary time to learn lisp, though. I’m now focusing most of my time to the .NETs, and slowly transferring my old VBA routines to C#. I’ll study C++ when free time allows. I have resigned myself to the fact that I’ll probably never learn Lisp. Here is a question for you: Do you plan to download the necessary file to activate VBA on you 2010 setup? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 21, 2009 Share Posted June 21, 2009 Here is a question for you: Do you plan to download the necessary file to activate VBA on you 2010 setup? I have considered learning VBA, as it doens't seem too far removed from LISP - as most of the methods used in LISP are VBA applicable, with just a different way of formatting the code. But now I am just thinking of focussing on C++, which would put me in my better standing to learn other languages. So, in answer to your question, probably not. Quote Link to comment Share on other sites More sharing options...
SEANT Posted June 21, 2009 Share Posted June 21, 2009 I can’t say I’d blame you. . . . certainly not at this stage of the game. Actually, I wonder what percentage of AutoCAD 2010 users has taken the opportunity to download those files. I have Inventor 2009 but haven’t invested much time in it yet. With VBA as one of a more limited number of API’s, I wonder if the Inventor community is more heavily vested in VBA and, as such, more frantic at it’s impending demise. Quote Link to comment Share on other sites More sharing options...
ronjonp Posted June 21, 2009 Share Posted June 21, 2009 Here is one I use daily to get nested layer names and other info ;;; AUTHOR ;;; Copyright© 2009 Ron Perez (ronperez ( a t ) gmail ( dot ) com) ;;; ;;;List nested objects info (defun c:q (/ x z msg plt lyr olyr descr plot dxf propsbyobject plot?) (defun plot? (ent /) (if (zerop (dxf 290 ent)) "NO" "Yes" ) ) (defun propsbyobject (ent / out) (setq out "") (foreach prop '((48 . "Ltype-Scale ") (6 . "Ltype ") (62 . "Color ")) (if (dxf (car prop) ent) (setq out (strcat (cdr prop) out)) ) ) (if (zerop (strlen out)) out (strcat "\n *Property BYOBJECT: " out) ) ) (defun dxf (x ename /) (cdr (assoc x (entget ename)))) (if (setq x (nentsel)) (progn (setq lyr (tblobjname "layer" (dxf 8 (car x))) olyr (vlax-ename->vla-object lyr) plt (plot? lyr) ) (if (/= (setq descr (vla-get-description olyr)) "") (setq descr (strcat "\n Description: " descr)) ) (setq msg (strcat "[ " (dxf 0 (car x)) " ]\n Layer: " (dxf 8 (car x)) "\n Color: " (itoa (dxf 62 lyr)) "\n Linetype: " (dxf 6 lyr) "\n Plottable: " plt descr (propsbyobject (car x)) "\n" "\n" ) ) (if (cadddr x) (setq msg (foreach z (cadddr x) (setq lyr (tblobjname "layer" (dxf 8 z)) olyr (vlax-ename->vla-object lyr) plt (plot? lyr) ) (if (/= (setq descr (vla-get-description olyr)) "") (setq descr (strcat "\n Description: " descr)) ) (setq msg (strcat "[ " (if (vlax-property-available-p (vlax-ename->vla-object z) 'path) (strcat "XREF - " (dxf 2 z)) (strcat "INSERT - " (dxf 2 z)) ) " ]\n Layer: " (dxf 8 z) "\n Color: " (itoa (dxf 62 lyr)) "\n Linetype: " (dxf 6 lyr) "\n Plottable: " plt descr (propsbyobject z) "\n" "\n" msg ) ) ) ) ) (alert msg) (princ msg) ) (princ "\nNothing selected...") ) (princ) ) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 21, 2009 Share Posted June 21, 2009 Or even: http://www.cadtutor.net/forum/showthread.php?t=36273 Quote Link to comment Share on other sites More sharing options...
muck Posted June 22, 2009 Author Share Posted June 22, 2009 VBA is prefered in this case. Quote Link to comment Share on other sites More sharing options...
doru10 Posted November 10, 2011 Share Posted November 10, 2011 Mr. Lee Mac Very interesting lisp your sites. I am looking for a lisp that I read the information entities (lines, polylines ...) on the layer (see dwg) and put them in the text (block with attributes). As shown in the drawing layer reading to be done by name and in the second case by name, color and line type. Respectfully, Doru LISP is much more concise... (defun c:getlay (/ ent) (and (setq ent (car (nentsel "\nSelect Entity: "))) (princ (strcat "\nLayer is: " (cdr (assoc 8 (entget ent)))))) (princ)) Information Layer.dwg Quote Link to comment Share on other sites More sharing options...
doru10 Posted November 24, 2011 Share Posted November 24, 2011 Hi ronjonp, Can change the lisp you posted, write the information layer in a block with attibuts (see attash). With respect. Here is one I use daily to get nested layer names and other info ;;; AUTHOR ;;; Copyright© 2009 Ron Perez (ronperez ( a t ) gmail ( dot ) com) ;;; ;;;List nested objects info (defun c:q (/ x z msg plt lyr olyr descr plot dxf propsbyobject plot?) (defun plot? (ent /) (if (zerop (dxf 290 ent)) "NO" "Yes" ) ) (defun propsbyobject (ent / out) (setq out "") (foreach prop '((48 . "Ltype-Scale ") (6 . "Ltype ") (62 . "Color ")) (if (dxf (car prop) ent) (setq out (strcat (cdr prop) out)) ) ) (if (zerop (strlen out)) out (strcat "\n *Property BYOBJECT: " out) ) ) (defun dxf (x ename /) (cdr (assoc x (entget ename)))) (if (setq x (nentsel)) (progn (setq lyr (tblobjname "layer" (dxf 8 (car x))) olyr (vlax-ename->vla-object lyr) plt (plot? lyr) ) (if (/= (setq descr (vla-get-description olyr)) "") (setq descr (strcat "\n Description: " descr)) ) (setq msg (strcat "[ " (dxf 0 (car x)) " ]\n Layer: " (dxf 8 (car x)) "\n Color: " (itoa (dxf 62 lyr)) "\n Linetype: " (dxf 6 lyr) "\n Plottable: " plt descr (propsbyobject (car x)) "\n" "\n" ) ) (if (cadddr x) (setq msg (foreach z (cadddr x) (setq lyr (tblobjname "layer" (dxf 8 z)) olyr (vlax-ename->vla-object lyr) plt (plot? lyr) ) (if (/= (setq descr (vla-get-description olyr)) "") (setq descr (strcat "\n Description: " descr)) ) (setq msg (strcat "[ " (if (vlax-property-available-p (vlax-ename->vla-object z) 'path) (strcat "XREF - " (dxf 2 z)) (strcat "INSERT - " (dxf 2 z)) ) " ]\n Layer: " (dxf 8 z) "\n Color: " (itoa (dxf 62 lyr)) "\n Linetype: " (dxf 6 lyr) "\n Plottable: " plt descr (propsbyobject z) "\n" "\n" msg ) ) ) ) ) (alert msg) (princ msg) ) (princ "\nNothing selected...") ) (princ) ) InfLayer.dwg 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.