Jump to content

Pick Entity to get it's Layer Name?


muck

Recommended Posts

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,

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

VBA.gif

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Here is one I use daily to get nested layer names and other info :D

 

;;; 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)
)

Link to comment
Share on other sites

  • 2 years later...

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

Link to comment
Share on other sites

  • 2 weeks later...

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 :D

 

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

Link to comment
Share on other sites

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