Fields Customising

Fields Customising

trevor_adams2
Participant Participant
1,141 Views
8 Replies
Message 1 of 9

Fields Customising

trevor_adams2
Participant
Participant

Hi There,

 

I'm currently trying to extract the RGB colour of a layer within AutoCAD but because the layer colour is set to ByLayer this is what is display in the field.

 

Layer colour - Field.JPG

 

I have found out when you select NamedObject and then select the Layer the Object ID is difference.

 

 Layer colour - Field22.JPG

 

So I decide to change to Object Id name in the early Field Expression and paste the everything in the formula box

 

Layer colour - Field2.JPG

 

As you can see above it is showing the RGB colour but its displaying #### in the field. Is there anything I can do to solve this?

 

 

Thanks

 

0 Likes
1,142 Views
8 Replies
Replies (8)
Message 2 of 9

rkmcswain
Mentor
Mentor
I think the answer is the same as it was 10 years ago.

http://forums.augi.com/showthread.php?36156-Layer-color-in-a-Field

R.K. McSwain     | CADpanacea | on twitter
0 Likes
Message 3 of 9

dbroad
Mentor
Mentor

What you want to do is not supported by the field command and field dialog.  It is however supported by fieldcodes when used in mtext.

 

Process:

1. Use the field dialog namedobject mechanism and choose the layer name you want to track.

2. Copyclip the fieldcode.

3. Start notepad

4. Paste the fieldcode into notepad.

5. Change "name" to "color.

6. Copyclip the fieldcode from notepad.

7. Start the mtext command.

8. Paste the fieldcode into the mtext object. 

 

Example fieldcode:  %<\AcObjProp Object(%<\_ObjId 588452320528>%).Color>%

Architect, Registered NC, VA, SC, & GA.
Message 4 of 9

trevor_adams2
Participant
Participant

Excellent, seems to work perfectly. 

 

I guess there no easy way to get a list of all the Layer names with their object numbers?

 

Thanks for your help.

0 Likes
Message 5 of 9

rkmcswain
Mentor
Mentor
Very nice @Anonymous !
R.K. McSwain     | CADpanacea | on twitter
0 Likes
Message 6 of 9

dbroad
Mentor
Mentor

@trevor.adams wrote:

Excellent, seems to work perfectly. 

 

I guess there no easy way to get a list of all the Layer names with their object numbers?


You're welcome.  As to your question, that depends on what you mean by "easy".  I prefer "possible".  Obtaining any object id is possible via customization (programming) or one at a time with the field dialog.  For layers, loop through the layer table or layer collection and make a list of the objectids.

 

 

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 7 of 9

dbroad
Mentor
Mentor

Thanks @rkmcswain

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 8 of 9

rkmcswain
Mentor
Mentor

I found some code I had that was doing something similar, so here is a quick and dirty stab at your thing.

 

  (setq *acad* (vlax-get-acad-object))
  (setq *cdoc* (vla-get-ActiveDocument *acad*))
  (setq *util* (vla-get-Utility *cdoc*))

(defun c:foo ( / q d n lst lays)
  (setq lst '())
  (setq lays (vla-get-Layers *cdoc*))
  (vlax-for q lays    
    (setq d (vlax-invoke-method *util* "GetObjectIDString" q :Vlax-false))
    (setq n (vla-get-Name q))
    (setq lst (cons (cons d n) lst))
  )
  (command "._text" (list 91000.0 51200.0) "0.0" "List")
  (foreach item lst
    (vl-cmdf "._text" "" (strcat "Layer Name = " (cdr item) " & Layer Color = " "%<\\AcObjProp Object(%<\\_ObjId " (car item) ">%).Color>%") "")
  )  
)

 ...and a partial screencap of the results.

 

resultlist.png

R.K. McSwain     | CADpanacea | on twitter
Message 9 of 9

trevor_adams2
Participant
Participant

Great, thanks @rkmcswain

 

0 Likes