Author Topic: Check if view exists...make another  (Read 2204 times)

0 Members and 1 Guest are viewing this topic.

jlogan02

  • Bull Frog
  • Posts: 327
Check if view exists...make another
« on: May 10, 2019, 12:05:35 PM »
Really simple code below to check if a view "Master_RM" exists, if it does make another view "MASTER" at PT1 PT2.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo1 ( / VDM PT1 PT2)
  2.  
  3. (setq pt1  '(0.0 0.0);;Master view
  4.       pt2  '(34.0 22.0)
  5.       );;this should go inside the (if...statement
  6.  
  7. (setq VDM (entget (cdr (assoc 330 (entget (tblobjname "VIEW" "MASTER_RM"))))))
  8.  (if
  9.    (TblObjName "VIEW" "MASTER_RM")
  10.      (command "-view" "window" "MASTER" pt1 pt2)
  11.     ;;)
  12.   );;if
  13. );;defun

Why does it work if I use this...
Code - Auto/Visual Lisp: [Select]
  1.  (TblObjName "VIEW" "MASTER_RM")

but if I use...
Code - Auto/Visual Lisp: [Select]
  1.  (TblObjName "VIEW" VDM)
it doesn't?

So eventually I need to create a dialog box driven option for the user or use
Code - Auto/Visual Lisp: [Select]
  1. (cond...
to achieve this using the code below...

Obviously missing error check and the usual suspects. This is to test the premise.

Code - Auto/Visual Lisp: [Select]
  1. (defun C:PPD_Views ( / PT1 PT2 PT3 PT4 PT5 PT6 PT7 PT8 PT10 PT11 PT12 PT13 PT14 PT15 PT16 PT9)
  2.   (setq pt1  '(0.0 0.0);;Master view
  3.         pt2  '(34.0 22.0)
  4.         pt3  '(0.0 25.0);;Master_rm view
  5.         pt4  '(0.0 47.0)
  6.         pt5  '(37.0 0.0);;INSTALL_1
  7.         pt6  '(71.0 22.0)
  8.         pt7  '(37.0 25.0);;INSTALL_1RM
  9.         pt8  '(71.0 47.0)
  10.         PT9  '(74.0 0.0);;INSTALL_2
  11.         PT10 '(108.0 22.0)
  12.         pt11 '(74.0 25.0);;INSTALL_2RM
  13.         pt12 '(108.0 47.0)
  14.         pt13 '(111.0 0.0);;INSTALL_3
  15.         pt14 '(145.0 22.0)
  16.         pt15 '(111.0 25.0);;INSTALL_3RM
  17.         pt16 '(145.0 47.0)
  18.         )
  19.   (command "-view" "window" "MASTER" pt1 pt2)
  20.   (command "-view" "window" "MASTER_RM" pt3 pt4)
  21.   (command "-view" "window" "INSTALL_1" pt5 pt6)
  22.   (command "-view" "window" "INSTALL_1RM" pt7 pt8)
  23.   (command "-view" "window" "INSTALL_2" pt9 pt10)
  24.   (command "-view" "window" "INSTALL_2RM" pt11 pt12)
  25.   (command "-view" "window" "INSTALL_3" pt13 pt14)
  26.   (command "-view" "window" "INSTALL_3RM" pt15 pt16)
  27.   (command "-layout" "t" "STA_CTL_PPD_Plot.dwt" "*")
  28.   (command "-layout" "d" "Layout*")
  29. )

Thanks in advance. Happy Mother's day to all you mothers and your mothers.

J. Logan
ACAD 2018

I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Check if view exists...make another
« Reply #1 on: May 10, 2019, 12:23:43 PM »
Maybe this makes sense:
Code - Auto/Visual Lisp: [Select]
  1. ;; This returns an entity list 'vdm'
  2. (setq vdm (entget (cdr (assoc 330 (entget (tblobjname "VIEW" "MASTER_RM"))))))
  3. ;; tblobjname needs a string like you have above '"MASTER_RM"' ?
  4. (tblobjname "VIEW" vdm)

You could also put those points and names into a list and make your views like so rather than settings all those variables.
Code - Auto/Visual Lisp: [Select]
  1. (foreach x '(("MASTER" (0.0 0.0) (34.0 22.0))
  2.              ("MASTER_RM" (0.0 25.0) (0.0 47.0))
  3.              ("INSTALL_1" (37.0 0.0) (71.0 22.0))
  4.              ("INSTALL_1RM" (37.0 25.0) (71.0 47.0))
  5.              ("INSTALL_2" (74.0 0.0) (108.0 22.0))
  6.              ("INSTALL_2RM" (74.0 25.0) (108.0 47.0))
  7.              ("INSTALL_3" (111.0 0.0) (145.0 22.0))
  8.              ("INSTALL_3RM" (145.0 47.0))
  9.             )
  10.   (command "-view" "window" (car x) (cadr x) (caddr x))
  11. )
« Last Edit: May 10, 2019, 12:32:23 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

jlogan02

  • Bull Frog
  • Posts: 327
Re: Check if view exists...make another
« Reply #2 on: May 10, 2019, 03:08:00 PM »
I was hoping lunch would make me smarter. All it did was make me sleepy and still dumb.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo1 ( / VDM PT1 PT2)
  2.  
  3. (setq vdm (getstring (tblobjname "VIEW" "MASTER_RM")))
  4.  (if
  5.    (tblobjname "VIEW" vdm)
  6.         (foreach x '(("MASTER" (0.0 0.0) (34.0 22.0))
  7.         )
  8.           (command "-view" "window" (car x) (cadr x) (caddr x))
  9.          )
  10.  );;if
  11. );;defun

Maybe this makes sense:
Code - Auto/Visual Lisp: [Select]
  1. ;; This returns an entity list 'vdm'
  2. (setq vdm (entget (cdr (assoc 330 (entget (tblobjname "VIEW" "MASTER_RM"))))))
  3. ;; tblobjname needs a string like you have above '"MASTER_RM"' ?
  4. (tblobjname "VIEW" vdm)

You could also put those points and names into a list and make your views like so rather than settings all those variables.
Code - Auto/Visual Lisp: [Select]
  1. (foreach x '(("MASTER" (0.0 0.0) (34.0 22.0))
  2.              ("MASTER_RM" (0.0 25.0) (0.0 47.0))
  3.              ("INSTALL_1" (37.0 0.0) (71.0 22.0))
  4.              ("INSTALL_1RM" (37.0 25.0) (71.0 47.0))
  5.              ("INSTALL_2" (74.0 0.0) (108.0 22.0))
  6.              ("INSTALL_2RM" (74.0 25.0) (108.0 47.0))
  7.              ("INSTALL_3" (111.0 0.0) (145.0 22.0))
  8.              ("INSTALL_3RM" (145.0 47.0))
  9.             )
  10.   (command "-view" "window" (car x) (cadr x) (caddr x))
  11. )
J. Logan
ACAD 2018

I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Check if view exists...make another
« Reply #3 on: May 10, 2019, 03:46:11 PM »
I was hoping lunch would make me smarter. All it did was make me sleepy and still dumb.

HAHA .. what are you still struggling with?

Why are you passing tblobjname with getstring?
Code - Auto/Visual Lisp: [Select]
  1. (setq vdm (getstring (tblobjname "VIEW" "MASTER_RM")))

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

jlogan02

  • Bull Frog
  • Posts: 327
Re: Check if view exists...make another
« Reply #4 on: May 10, 2019, 03:50:19 PM »
Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo1 ( / VDM PT1 PT2)
  2.  
  3. (setq vdm (getstring (tblobjname "VIEW" "MASTER_RM")))
  4.  (if
  5.    (tblobjname "VIEW" vdm)
  6.         (foreach x '(("MASTER" (0.0 0.0) (34.0 22.0))
  7.         )
  8.           (command "-view" "window" (car x) (cadr x) (caddr x))
  9.          )
  10.  );;if
  11. );;defun

I'm clueless. This should be straight forward...
J. Logan
ACAD 2018

I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Check if view exists...make another
« Reply #5 on: May 10, 2019, 03:53:05 PM »
Maybe this? Will make all your views.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo nil
  2.   (foreach x '(("MASTER" (0.0 0.0) (34.0 22.0))
  3.                ("MASTER_RM" (0.0 25.0) (0.0 47.0))
  4.                ("INSTALL_1" (37.0 0.0) (71.0 22.0))
  5.                ("INSTALL_1RM" (37.0 25.0) (71.0 47.0))
  6.                ("INSTALL_2" (74.0 0.0) (108.0 22.0))
  7.                ("INSTALL_2RM" (74.0 25.0) (108.0 47.0))
  8.                ("INSTALL_3" (111.0 0.0) (145.0 22.0))
  9.                ("INSTALL_3RM" (145.0 47.0))
  10.               )
  11.     (command "-view" "window" (car x) (cadr x) (caddr x))
  12.   )
  13.   (princ)
  14. )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

jlogan02

  • Bull Frog
  • Posts: 327
Re: Check if view exists...make another
« Reply #6 on: May 10, 2019, 04:04:28 PM »
Hmmph...Something to do with how I was using VLide. I hadn't actually run the routine in AutoCAD by drag and drop. I was loading from Vlide and it would act like it worked but not acutally do anything.

I also never tried just the foreach method...by itself.

Thanks.
J. Logan
ACAD 2018

I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Check if view exists...make another
« Reply #7 on: May 10, 2019, 04:18:48 PM »
Hmmph...Something to do with how I was using VLide. I hadn't actually run the routine in AutoCAD by drag and drop. I was loading from Vlide and it would act like it worked but not acutally do anything.

I also never tried just the foreach method...by itself.

Thanks.
Glad to help :). Anytime you're setting that many variables most likely a list is a cleaner approach.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC