Author Topic: Get layout tab list without using Active X?  (Read 831 times)

0 Members and 1 Guest are viewing this topic.

jmcshane

  • Newt
  • Posts: 83
Get layout tab list without using Active X?
« on: March 28, 2022, 11:59:17 AM »
Hi guys,

Haven't posted here in a while. Just trying figure out if there is a way to get a list of layout tabs without using active X or the Layoutlist command.
Looking at doing some acoreconsole work and it doesn't handle activeX.
I am trying to delete layouts which don't have the same name as the drawing.

Would be grateful if someone could point me in the right direction.

Cheers

John
« Last Edit: March 28, 2022, 12:05:42 PM by jmcshane »
John.

Civil 3D 2021. Windows 10

VovKa

  • Swamp Rat
  • Posts: 1468
  • Ukraine
Re: Get layout tab list without using Active X?
« Reply #1 on: March 28, 2022, 12:06:23 PM »
(dictsearch (namedobjdict) "ACAD_LAYOUT")

jmcshane

  • Newt
  • Posts: 83
Re: Get layout tab list without using Active X?
« Reply #2 on: March 28, 2022, 12:16:20 PM »
Oh now that's neat!!

Please excuse my next question as its been a few years since I coded properly and am a bit rusty.....

I was going to stick the result of this into a list and just delete whatever layout didn't match with a foreach loop, how can I just grab all the assoc 3 pairs?

Thanks in advance,

John
John.

Civil 3D 2021. Windows 10

ronjonp

  • Needs a day job
  • Posts: 7436
Re: Get layout tab list without using Active X?
« Reply #3 on: March 28, 2022, 02:19:14 PM »
Oh now that's neat!!

Please excuse my next question as its been a few years since I coded properly and am a bit rusty.....

I was going to stick the result of this into a list and just delete whatever layout didn't match with a foreach loop, how can I just grab all the assoc 3 pairs?

Thanks in advance,

John
Just check within your loop like so:
Code - Auto/Visual Lisp: [Select]
  1. (foreach x (dictsearch (namedobjdict) "ACAD_LAYOUT")
  2.   (if (= 3 (car x))
  3.       ;; Do stuff
  4.   )
  5. )
« Last Edit: March 29, 2022, 11:43:37 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2022

Custom Build PC

jmcshane

  • Newt
  • Posts: 83
Re: Get layout tab list without using Active X?
« Reply #4 on: March 28, 2022, 05:48:07 PM »
Thanks a million Guys, that's exactly what I needed.
Really appreciate the help.

John
John.

Civil 3D 2021. Windows 10

Lee Mac

  • Seagull
  • Posts: 12696
  • London, England
Re: Get layout tab list without using Active X?
« Reply #5 on: March 28, 2022, 07:19:48 PM »
You could alternatively use dictnext in a manner analogous to how you might use tblnext to iterate over a symbol table, e.g.:
Code - Auto/Visual Lisp: [Select]
  1. (defun mylayoutlist ( / dic itm rtn )
  2.     (if (setq dic (cdr (assoc -1 (dictsearch (namedobjdict) "acad_layout"))))
  3.         (while (setq itm (dictnext dic (not itm)))
  4.             (setq rtn (cons (cdr (assoc 1 (member '(100 . "AcDbLayout") itm))) rtn))
  5.         )
  6.     )
  7.     (reverse rtn)
  8. )

Stefan

  • Bull Frog
  • Posts: 303
Re: Get layout tab list without using Active X?
« Reply #6 on: March 29, 2022, 05:03:56 AM »
What is wrong with
Code - Auto/Visual Lisp: [Select]

jmcshane

  • Newt
  • Posts: 83
Re: Get layout tab list without using Active X?
« Reply #7 on: March 29, 2022, 09:03:29 AM »
What is wrong with
Code - Auto/Visual Lisp: [Select]

(LayoutList) works fine when used normally, but for some reason it wouldn't work when using acoreconsole.
I'm thinking it might be based on ActiveX which isn't supported in acoreconsole as far as I know.

Cheers,

John
John.

Civil 3D 2021. Windows 10

jmcshane

  • Newt
  • Posts: 83
Re: Get layout tab list without using Active X?
« Reply #8 on: March 29, 2022, 09:06:20 AM »
You could alternatively use dictnext in a manner analogous to how you might use tblnext to iterate over a symbol table, e.g.:
Code - Auto/Visual Lisp: [Select]
  1. (defun mylayoutlist ( / dic itm rtn )
  2.     (if (setq dic (cdr (assoc -1 (dictsearch (namedobjdict) "acad_layout"))))
  3.         (while (setq itm (dictnext dic (not itm)))
  4.             (setq rtn (cons (cdr (assoc 1 (member '(100 . "AcDbLayout") itm))) rtn))
  5.         )
  6.     )
  7.     (reverse rtn)
  8. )

Thanks Lee, you'll have to excuse my lack of knowledge here, but what benefits would this have over the other way?

Thanks in advance,

John
John.

Civil 3D 2021. Windows 10

Lee Mac

  • Seagull
  • Posts: 12696
  • London, England
Re: Get layout tab list without using Active X?
« Reply #9 on: March 29, 2022, 10:17:28 AM »
You could alternatively use dictnext in a manner analogous to how you might use tblnext to iterate over a symbol table, e.g.:
Code - Auto/Visual Lisp: [Select]
  1. (defun mylayoutlist ( / dic itm rtn )
  2.     (if (setq dic (cdr (assoc -1 (dictsearch (namedobjdict) "acad_layout"))))
  3.         (while (setq itm (dictnext dic (not itm)))
  4.             (setq rtn (cons (cdr (assoc 1 (member '(100 . "AcDbLayout") itm))) rtn))
  5.         )
  6.     )
  7.     (reverse rtn)
  8. )

Thanks Lee, you'll have to excuse my lack of knowledge here, but what benefits would this have over the other way?

No particular benefit, just another way to skin the cat  :-)

VovKa

  • Swamp Rat
  • Posts: 1468
  • Ukraine
Re: Get layout tab list without using Active X?
« Reply #10 on: March 29, 2022, 11:45:12 AM »
I'm thinking it might be based on ActiveX which isn't supported in acoreconsole as far as I know.
(layoutlist) is defined inside acapp.arx which is not loaded by acoreconsole

jmcshane

  • Newt
  • Posts: 83
Re: Get layout tab list without using Active X?
« Reply #11 on: March 29, 2022, 12:26:59 PM »
Thanks guys, really appreciate all the information and help.

John
John.

Civil 3D 2021. Windows 10

BlackBox

  • King Gator
  • Posts: 3756
Re: Get layout tab list without using Active X?
« Reply #12 on: March 30, 2022, 07:02:29 AM »
I'm thinking it might be based on ActiveX which isn't supported in acoreconsole as far as I know.
(layoutlist) is defined inside acapp.arx which is not loaded by acoreconsole

So simply load it in the Script:

Code: [Select]
_.arx L "acapp.arx"
(setq foo (layoutlist))

Core Console supports loading ARX/.NET assemblies.

Cheers
"How we think determines what we do, and what we do determines what we get."

jmcshane

  • Newt
  • Posts: 83
Re: Get layout tab list without using Active X?
« Reply #13 on: March 30, 2022, 09:09:37 AM »
Thanks BlackBox, I didn't know you could do that.
John.

Civil 3D 2021. Windows 10