Jump to content

Highligting a selection


Manila Wolf

Recommended Posts

I have the following lisp. When running the code, it first asks to select a dimension, then asks to select an attribute block to import the value of the dimension.

 

My question is: - How to modify the code to make the selected dimension highlighted, like standard AutoCAD selection highlighting? Right now the selected dimension is not highlighted, so difficult to know if it is selected or not. I hope this is a simple solution that someone can help me with.

 

This may be more complex, but I wonder also if the code could be modified to be able to place the dimension text in any specified attribute tag. Right now it only places the dimension text in the first line of an attribute having multiple tags.

In this particular case a tag name "UTUNIT" is specified in the code, but only works if "UTUNIT" is located in the first line of the attribute.

 

 

(defun C:dimatt (/ dim diminfo dimtext ss ent entinfo)
(setq dim (entsel "\n Select Dimension: "))
(setq diminfo (entget (car dim)))
(if (= (cdr (assoc 1 diminfo)) "")
(setq dimtext (rtos (cdr (assoc 42 diminfo))))
(setq dimtext (cdr (assoc 1 entinfo)))
)
(setq ss (ssget))
(setq ent (entnext (ssname ss 0)))
(setq entinfo (entget ent))
(while
(and ent
(= (cdr (assoc 0 entinfo)) "ATTRIB")
)
(if (= (cdr (assoc 2 entinfo)) (strcase "UTUNIT"))
(progn
(entmod (subst (cons 1 dimtext) (assoc 1 entinfo) entinfo))
(entupd ent)
(setq ent nil)
)
(setq ent (entnext ent))
)
)
(princ)
)

 

Thanks to anybody who can help.

Link to comment
Share on other sites

Mircea,

 

Thanks for your reply.

 

Pardon my ignorance and lack of lisp knowledge, but where in the code would this be inserted?

Link to comment
Share on other sites

You may add it like:

(defun C:dimatt ( / dim diminfo dimtext ss ent entinfo)
(setq dim (entsel "\n Select Dimension: "))
[color=blue](redraw (car dim) 3)
[/color](setq diminfo (entget (car dim)))
(if (= (cdr (assoc 1 diminfo)) "")
(setq dimtext (rtos (cdr (assoc 42 diminfo))))
(setq dimtext (cdr (assoc 1 entinfo)))
)
[color=blue](prompt "\nSelect block to export value:")
[/color](setq ss (ssget))
(setq ent (entnext (ssname ss 0)))
(setq entinfo (entget ent))
(while
(and ent
(= (cdr (assoc 0 entinfo)) "ATTRIB")
)
(if (= (cdr (assoc 2 entinfo)) (strcase "UTUNIT"))
(progn
(entmod (subst (cons 1 dimtext) (assoc 1 entinfo) entinfo))
(entupd ent)
(setq ent nil)
)
(setq ent (entnext ent))
)
)
[color=blue](redraw (car dim) 4)
[/color](princ)
)

 

Regards,

Mircea

Link to comment
Share on other sites

I have the following lisp. When running the code, it first asks to select a dimension, then asks to select an attribute block to import the value of the dimension.

 

Thanks to anybody who can help.

 

Consider this [quickly written]

 

(defun c:test  ( / atsel dim str atb e b)
(vl-load-com)
     (setq atsel (ssadd))
     (if (and
               (setq dim (ssget ":S:E" '((0 . "DIMENSION"))))
               (setq str (rtos (vla-get-measurement
                                     (setq e    (vlax-ename->vla-object
                                                      (ssname dim
                                                              0))))))
               (not (vla-Highlight e :vlax-true))
               )
           (progn
                 (while (setq atb  (nentselp
                                         "\nSelect Attribute value to replace: "))
                       (if (eq (cdr (assoc 0 (entget (setq at   (Car atb))))) "ATTRIB")
                             (progn (ssadd at atsel)(redraw at 3))
                             )
                       )
                 (repeat (Setq i (sslength atsel))
                       (vla-put-textstring
                             (vlax-ename->vla-object
                                   (setq b (ssname atsel
                                                   (setq i    (1- i)))))
                             str)
                       (redraw b 4)
                       )
                 (vla-Highlight e :vlax-false)
                 )
           )(princ)
     )

 

HTH

Link to comment
Share on other sites

Mircea, many thanks for the revised code. I tried it and it works. I hope I can find time to study and learn the reasoning.

I appreciate your time and help.

 

pBe......

What can I say? Your code is far superior to the original that I am using.

Not for the first time you have given me everything I have asked for.

Sincere thanks.

 

If you guys are ever in Manila, contact me here. The beers are on me.

 

:beer:

Link to comment
Share on other sites

Mircea, many thanks for the revised code. I tried it and it works. I hope I can find time to study and learn the reasoning.

I appreciate your time and help.

 

You are entirely welcome!

 

Regards,

Mircea

Link to comment
Share on other sites

pBe......

What can I say? Your code is far superior to the original that I am using.

Not for the first time you have given me everything I have asked for.

Sincere thanks.

 

Its nothing really, i just made it generic is all

 

If you guys are ever in Manila, contact me here. The beers are on me.

:beer:

 

I just might take you up on that offer one of these days Manila Wolf

 

:beer:

Link to comment
Share on other sites

Here is my version, using a Field:

;; Link Dimension to Attribute  -  Lee Mac
;; Prompts for selection of a Dimension and references the Dimension
;; value using a Field located in a selected block attribute.

(defun c:Dim2Att ( / *error* ad at el en g1 g2 gr ms ob p1 st )
   
   (defun *error* ( msg )
       (if en (redraw en 4))
       (if ad (vla-endundomark ad))
       (if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*"))
           (princ (strcat "\nError: " msg))
       )
       (redraw) (princ)
   )
   
   (while
       (progn (setvar 'ERRNO 0) (setq en (car (entsel "\nSelect Dimension to Link: ")))
           (cond
               (   (= 7 (getvar 'ERRNO))
                   (princ "\nMissed, try again.")
               )
               (   (eq 'ENAME (type en))
                   (if (not (wcmatch (cdr (assoc 0 (entget en))) "*DIMENSION"))
                       (princ "\nObject is not a Dimension.")
                   )
               )
           )
       )
   )
   (if en
       (progn
           (setq ad (vla-get-activedocument (vlax-get-acad-object))
                 el (entget en)
                 p1 (trans (cdr (assoc 11 el)) en 1)
                 ob (vlax-ename->vla-object en)
                 st (strcat
                        "%<\\AcObjProp Object(%<\\_ObjId "
                        (if
                            (and
                                (vl-string-search "64" (getenv "PROCESSOR_ARCHITECTURE"))
                                (vlax-method-applicable-p (vla-get-utility ad) 'getobjectidstring)
                            )
                            (vla-getobjectidstring (vla-get-utility ad) ob :vlax-false)
                            (itoa (vla-get-objectid ob))
                        )
                        (if (eq "" (cdr (assoc 1 el)))
                            ">%).Measurement \\f \"%lu6\">%"
                            ">%).TextOverride>%"
                        )
                    )
           )
           (vla-startundomark ad)
           (redraw en 3)
           (princ (setq ms "\nSelect Attribute to Link to Dimension: "))
           (while
               (progn
                   (setq gr (grread t 13 2)
                         g1 (car  gr)
                         g2 (cadr gr)
                   )
                   (cond
                       (   (= 5 g1)
                           (redraw)
                           (grdraw p1 g2 3 1)
                           t
                       )
                       (   (= 3 g1)
                           (redraw)
                           (if (setq at (car (nentselp g2)))
                               (if (eq "ATTRIB" (cdr (assoc 0 (entget at))))
                                   (progn
                                       (vla-put-textstring (vlax-ename->vla-object at) st)
                                       (vl-cmdf "_.updatefield" at "")
                                       (princ ms)
                                   )
                                   (princ (strcat "\nObject is not an Attribute." ms))
                               )
                               (princ (strcat "\nMissed, try again." ms))
                           )
                           t
                       )
                   )
               )
           )
           (redraw en 4)
           (redraw)
           (vla-endundomark ad)
       )
   )
   (princ)
)
(vl-load-com) (princ)
 
Edited by Lee Mac
  • Like 1
Link to comment
Share on other sites

Lee, that really is very good indeed. I particularly like the trailing line feature. Nice touch. Makes things so clear visually. Thank you so much.

 

On a similar theme, I find I extensively use your MacAttV3-1.lsp inconjunction with the dim to attribute lisp. After updating the attribute I then extract usually over multiple drawings. I must take this opportunity to also sincerely thank you for that.

 

I wonder if you have anything in your archive that modernises the attached tagcount lisp.

This reads blocks in an open drawing then lists the text in the tag in an antiquated table. The list is in alphabetical order and compounds quantities. I really find this useful, as I do not have to extract to Excel, sort and then import back into a drawing.

 

I am aware that I am always asking for help on this excellent forum, but if you do have an archived code that does something like this, something that will not take up your time, I would once again be very grateful.

I barely have any lisp knowledge at all, but I read many post's on here and find myself saving codes even if I do not really need them. I am hoping that if ever my work load eases up, I can devote some time to learning the concepts of lisp. Time is always the enemy.

 

Lee, same for you. Beers on me if you ever find yourself in the Manila area. Cheers.

 

:beer:

TAGCOUNT.LSP

Link to comment
Share on other sites

Lee, that really is very good indeed. I particularly like the trailing line feature. Nice touch. Makes things so clear visually. Thank you so much.

 

You're very welcome, I enjoyed writing that one :)

 

On a similar theme, I find I extensively use your MacAttV3-1.lsp inconjunction with the dim to attribute lisp. After updating the attribute I then extract usually over multiple drawings. I must take this opportunity to also sincerely thank you for that.

 

Again, you're welcome - I'm pleased that you are able to benefit from my programs. :)

 

I wonder if you have anything in your archive that modernises the attached tagcount lisp.

This reads blocks in an open drawing then lists the text in the tag in an antiquated table. The list is in alphabetical order and compounds quantities. I really find this useful, as I do not have to extract to Excel, sort and then import back into a drawing.

 

I've only glanced over the code in your TagCount.lsp, but, it sounds like this may help:

 

http://lee-mac.com/countattributevalues.html

 

Lee, same for you. Beers on me if you ever find yourself in the Manila area. Cheers.

 

I might just take you up on that someday ;)

 

Nice idea using fields. :thumbsup:

 

Cheers pBe :)

Link to comment
Share on other sites

Hi Lee,

 

Thanks for pointing me to your CountAttributeValues program. It works very well and does indeed do much the same as my TagCount Lisp.

 

Is there any tricks to set the text height and text style in the resultant table?

 

Rgds

 

MW

Link to comment
Share on other sites

Lee,

Thank you for sharing Dim2Att.lsp this is a great tool.

We use fractional dimensions with the inch mark in the Dim suffixsetting and the Dim2Att inserts the dimension without the inch mark.

Can you add to the Dim2Att.lsp that if the dimension style isfractional to add the inch mark. I would not want to add just anything from Dimsuffix that may hold the words like Length, width, Height or many others.

Thanks

E

Link to comment
Share on other sites

Hi EBROWN,

 

You're very welcome :)

 

Concerning the inch mark, this may be easier to include by modifying the Field Formatting code used in the program.

 

Currently the Field formatting code is set to (Line 47):

 

[color=MAROON]%lu6[/color]

This means: "Use Current Units & Precision"

 

However, you can change this to...

 

%lu4

...to use Architectural Units, or...

 

%lu3

...for Engineering Units.

 

Otherwise, you can add a " Suffix and keep the units as they are by changing the code to:

 

%lu6%ps[,\"]

I hope this helps,

 

Lee

Link to comment
Share on other sites

Thanks, Lee

 

I am having a problem with the coding of a fractional dimension with 1/32" precision

and an inch mark. this is the field expression

%<\AcObjProp.16.2 Object(%<\_ObjId 8796088142000>%).Measurement \f "%lu5%pr5%ps[,\"]">%

 

and this is what I put in the code

 

.Measurement [url="file://\\f"]\\f[/url] \"%lu5%pr5%ps\"[,\"]\">%"

 

the results are: #### instead of the 17 1/32"

 

when i double click on the #### the field name: is Object Property" is Alt enabled Format: is (none)

Please advis to the correct code.

 

Thank you for your help.

Link to comment
Share on other sites

If the field expression as displayed in the Field Command dialog is:

 

%<\AcObjProp.16.2 Object(%<\_ObjId 8796088142000>%).Measurement \f "%lu5%pr5%ps[,\"]">%

Then the code used in the program should end as:

 

.Measurement \\f \"%lu5%pr5%ps[,\\\"]\">%

 

Hence the code segment will look like:

 

                         (if (eq "" (cdr (assoc 1 el)))
                            ">%).Measurement \\f \"%lu5%pr5%ps[,\\\"]\">%"
                            ">%).TextOverride>%"
                        )

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