Author Topic: How to extract all names of Mleaders ?  (Read 2279 times)

0 Members and 1 Guest are viewing this topic.

Coder

  • Swamp Rat
  • Posts: 827
How to extract all names of Mleaders ?
« on: May 14, 2012, 02:10:32 AM »
Hello everyone .  :-)

I would like to extract all names of Mleaders of my drawing .  with the use of function ( dictnext ) :-)

Can anyone help please ?

Thanks
« Last Edit: May 14, 2012, 02:21:16 AM by coder »

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: How to extract all names of Mleaders ?
« Reply #1 on: May 14, 2012, 02:56:47 AM »
By names, are you referring to MLeader styles?

If so, you first need to obtain the MLStyle ename, then use dictnext on that:
Code: [Select]
(setq mldict (dictsearch (namedobjdict) "ACAD_MLEADERSTYLE")) ;Get the MLeader Style container dictionary
(setq ml (dictnext (cdr (assoc -1 mldict)) t)) ;Get the first MLeader Style
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Lee Mac

  • Seagull
  • Posts: 12929
  • London, England
Re: How to extract all names of Mleaders ?
« Reply #2 on: May 14, 2012, 06:45:18 AM »
Treat dictnext as you would tblnext

Coder

  • Swamp Rat
  • Posts: 827
Re: How to extract all names of Mleaders ?
« Reply #3 on: May 16, 2012, 08:25:09 AM »
Hi .

Yes irneb , I mean MLeader styles names . :-)

and I couldn't come up with any solution . :oops:

Thanks a lot

Lee Mac

  • Seagull
  • Posts: 12929
  • London, England
Re: How to extract all names of Mleaders ?
« Reply #4 on: May 16, 2012, 08:32:07 AM »
Yes irneb , I mean MLeader styles names . :-)

and I couldn't come up with any solution . :oops:

Post the code you have and we can help  :-)

Coder

  • Swamp Rat
  • Posts: 827
Re: How to extract all names of Mleaders ?
« Reply #5 on: May 16, 2012, 08:40:58 AM »
Hi Lee .

I didn't write any code yet to extract the Mleader style names , because I couldn't find the dxf code for the Mleader Style name .

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: How to extract all names of Mleaders ?
« Reply #6 on: May 16, 2012, 08:54:43 AM »
If you only want the names, then it's the xrecord entries inside the main MLStyle dictionary. Here's a way to obtain a list of all the MLeader styles in the current drawing:
Code - Auto/Visual Lisp: [Select]
  1.         (vl-remove-if-not
  2.           '(lambda (c) (= (car c) 3))
  3.           (dictsearch (namedobjdict) "ACAD_MLEADERSTYLE")))
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Coder

  • Swamp Rat
  • Posts: 827
Re: How to extract all names of Mleaders ?
« Reply #7 on: May 16, 2012, 09:00:55 AM »
That's very good irneb .  :-)

You did it with dictsearch , I can't understand that advanced way .  :lol:

only if it is possible , can you explain it for me please ?

Many Thanks for you

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: How to extract all names of Mleaders ?
« Reply #8 on: May 16, 2012, 10:05:46 AM »
To explain: The dictsearch gives the DXF list of the entile MLeaderStyle dictionary. This contains an item (3 . "StyleName") followed by an item (350 . <Entity name: ###>) for each entry in that dictionary. The 350 code refers to the entity which defines the style, the 3 code is the name of that entry - and in this case the same as the name of the style.

Now the "advanced" idea is how I extract only the names from that entire DXF list:
  • The vl-remove-if-not removes all items from a list if a predicate function returns nil for that item.
  • The lambda is an unnamed function. I could have declared it as a normal defun, but that would be too much typing. It simply checks if the car of the item is 3.
  • The mapcar performs a function on each item in the list. In this case it cdr's each item.
So the dictsearch list might be something like this:
Code: [Select]
((-1 . <Entity name: 7ffffbb31c0>) (0 . "DICTIONARY") (5 . "4B4") (102 .
"{ACAD_REACTORS") (330 . <Entity name: 7ffffbb18b0>) (102 . "}") (330 . <Entity
name: 7ffffbb18b0>) (100 . "AcDbDictionary") (280 . 0) (281 . 1) (3 . "AR-LDR")
(350 . <Entity name: 7ffffb1fe40>) (3 . "ARLDR") (350 . <Entity name:
7ffffb0be00>) (3 . "DETREF-A") (350 . <Entity name: 7ffffb0be10>) (3 .
"Standard") (350 . <Entity name: 7ffffb28a20>) (3 . "Xref$0$RSA-ARROW-2") (350
. <Entity name: 7ffffb1fe50>))

Then the list returned through the vl-remove-if-not becomes this:
Code: [Select]
((3 . "AR-LDR") (3 . "ARLDR") (3 . "DETREF-A") (3 . "Standard") (3 .
"Xref$0$RSA-ARROW-2"))
And finally the mapcar returns this:
Code: [Select]
("AR-LDR" "ARLDR" "DETREF-A" "Standard" "Xref$0$RSA-ARROW-2")
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Coder

  • Swamp Rat
  • Posts: 827
Re: How to extract all names of Mleaders ?
« Reply #9 on: May 16, 2012, 12:50:40 PM »
Thank you irneb for the great explanation  :-)

But with function dictnext I could find the style name with dxf 3 or so .

Code: [Select]
(dictnext (namedobjdict) "ACAD_MLEADERSTYLE")
return

Code: [Select]
((-1 . <Entity name: 7ffffb03c30>) (0 . "DICTIONARY") (5 . "73")
(102 . "{ACAD_REACTORS") (330 . <Entity name: 7ffffb038c0>) (102 . "}")
(330 . <Entity name: 7ffffb038c0>) (100 . "AcDbDictionary") (280 . 0) (281 . 1))

Thank you

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: How to extract all names of Mleaders ?
« Reply #10 on: May 16, 2012, 01:03:24 PM »
No if you use dictnext on (namedobjdict) then you'll get the "next" dictionary in the drawing. Notice the 2nd argument in dictnext is if it returns the first, or the next since its last call. This argument is read as omitted or nil - means return next, anything else means return the first.

So what you see there is the first dictionary in the drawnig. It might even have nothing to do with MLeaders at all. E.g. the first dictionary in a blank DWG for me is this:
Code: [Select]
Command: (dictnext (namedobjdict) "ACAD_MLEADERSTYLE")
((-1 . <Entity name: 7ffffb059e0>) (0 . "XRECORD") (5 . "216") (102 .
"{ACAD_REACTORS") (330 . <Entity name: 7ffffb038c0>) (102 . "}") (330 . <Entity
name: 7ffffb038c0>) (100 . "AcDbXrecord") (280 . 1) (300 . "ACD") (300 .
"2012") (300 . "REVITS_F_S"))

Note that 330 code? It points to the owner dictionary. So doing this:
Code: [Select]
Command: (entget (cdr (assoc 330 (dictnext (namedobjdict) "ACAD_MLEADERSTYLE"))))
((-1 . <Entity name: 7ffffb038c0>) (0 . "DICTIONARY") (330 . <Entity name: 0>)
(5 . "C") (100 . "AcDbDictionary") (280 . 0) (281 . 1) (3 .
"ACAD_CIP_PREVIOUS_PRODUCT_INFO") (350 . <Entity name: 7ffffb059e0>) (3 .
"ACAD_COLOR") (350 . <Entity name: 7ffffb03bb0>) (3 . "ACAD_GROUP") (350 .
<Entity name: 7ffffb038d0>) (3 . "ACAD_LAYOUT") (350 . <Entity name:
7ffffb039a0>) (3 . "ACAD_MATERIAL") (350 . <Entity name: 7ffffb03ba0>) (3 .
"ACAD_MLEADERSTYLE") (350 . <Entity name: 7ffffb05150>) (3 . "ACAD_MLINESTYLE")
(350 . <Entity name: 7ffffb03970>) (3 . "ACAD_PLOTSETTINGS") (350 . <Entity
name: 7ffffb03990>) (3 . "ACAD_PLOTSTYLENAME") (350 . <Entity name:
7ffffb038e0>) (3 . "ACAD_SCALELIST") (350 . <Entity name: 7ffffb050c0>) (3 .
"ACAD_TABLESTYLE") (350 . <Entity name: 7ffffb03c60>) (3 . "ACAD_VISUALSTYLE")
(350 . <Entity name: 7ffffb03ef0>) (3 . "AcDbVariableDictionary") (350 .
<Entity name: 7ffffb03ae0>))

This is the same as doing:
Code: [Select]
(entget (namedobjdict))
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.