Author Topic: Copy viewport and linked Objects  (Read 1548 times)

0 Members and 1 Guest are viewing this topic.

CADwiesel

  • Newt
  • Posts: 46
  • Wir machen das Mögliche unmöglich
Copy viewport and linked Objects
« on: October 07, 2022, 08:48:31 AM »
Hello all,
I have copied a layout that contains a viewport (New Layout).
In the viewport there is an object in model space.
Now I copy this object to another place in the model space.

Her comes my question...
in my previously copied layout with the viewport (new layout), I want now to have the same view on the copied object as the 'old' viewport has on the 'old' object.

The whole thing should not work via commands or switching to the layouts or AF's, but programmatically via Lisp/Vlisp.
In my manual attempts I noticed that the only difference between the two AF's is the dxf 12 an 17. But these Points couldn't be changed by subst, and they are not in a vl-propetry list.
However, I don't know how to calculate this point, let alone what it should even mean.
So how can i point to the new view using (V)Lisp?

Thanks
Gruß
CADwiesel
Besucht uns im CHAT

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: Copy viewport and linked Objects
« Reply #1 on: October 07, 2022, 11:12:33 AM »
I suppose this is what you're looking for :

Code - Auto/Visual Lisp: [Select]
  1. (defun c:copyobjs+matchlayout ( / cmd vp vx doc v vs vc ss bp ep vec )
  2.  
  3.  
  4.   (defun *error* ( m )
  5.     (if (= 8 (logand 8 (getvar (quote undoctl))))
  6.       (if command-s
  7.         (command-s "_.UNDO" "_E")
  8.         (vl-cmdf "_.UNDO" "_E")
  9.       )
  10.     )
  11.     (if cmd
  12.       (setvar (quote cmdecho) cmd)
  13.     )
  14.     (if m
  15.       (prompt m)
  16.     )
  17.     (princ)
  18.   )
  19.  
  20.   (setq cmd (getvar (quote cmdecho)))
  21.   (setvar (quote cmdecho) 0)
  22.   (if (= 8 (logand 8 (getvar (quote undoctl))))
  23.     (if command-s
  24.       (command-s "_.UNDO" "_E")
  25.       (vl-cmdf "_.UNDO" "_E")
  26.     )
  27.   )
  28.   (if command-s
  29.     (command-s "_.UNDO" "_M")
  30.     (vl-cmdf "_.UNDO" "_M")
  31.   )
  32.   (if
  33.     (and
  34.       (setq vp (car (entsel "\nPick VIEWPORT in Layout...")))
  35.       (= (cdr (assoc 0 (setq vx (entget vp)))) "VIEWPORT")
  36.     )
  37.     (progn
  38.       (vla-put-activepviewport (setq doc (vla-get-document (setq v (vlax-ename->vla-object vp)))) v)
  39.       (setq vs (getvar (quote viewsize)))
  40.       (setq vc (getvar (quote viewctr)))
  41.       (if
  42.         (and
  43.           (setq ss (ssget "_:L"))
  44.           (setq bp (getpoint "\nPick or specify base point for copying : "))
  45.         )
  46.         (progn
  47.           (vl-cmdf "_.COPY" ss "" "_non" bp)
  48.           (while (< 0 (getvar (quote cmdactive)))
  49.             (vl-cmdf "\\")
  50.           )
  51.           (setq ep (getvar (quote lastpoint)))
  52.           (setq vec (mapcar (function -) ep bp))
  53.           (vlax-invoke-method
  54.             (vlax-get-acad-object)
  55.             (quote zoomcenter)
  56.             (vlax-3d-point (mapcar (function +) (trans vc 1 0) (trans vec 1 0 t)))
  57.             vs
  58.           )
  59.           (vla-put-mspace doc 0)
  60.         )
  61.       )
  62.       (prompt "\nFor UNDO - type \"UNDO\" - \"Back\" option...")
  63.     )
  64.   )
  65.   (*error* nil)
  66. )
  67.  

M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

kruuger

  • Swamp Rat
  • Posts: 635
Re: Copy viewport and linked Objects
« Reply #2 on: October 12, 2022, 05:38:04 PM »
Hello all,
I have copied a layout that contains a viewport (New Layout).
In the viewport there is an object in model space.
Now I copy this object to another place in the model space.

Her comes my question...
in my previously copied layout with the viewport (new layout), I want now to have the same view on the copied object as the 'old' viewport has on the 'old' object.

The whole thing should not work via commands or switching to the layouts or AF's, but programmatically via Lisp/Vlisp.
In my manual attempts I noticed that the only difference between the two AF's is the dxf 12 an 17. But these Points couldn't be changed by subst, and they are not in a vl-propetry list.
However, I don't know how to calculate this point, let alone what it should even mean.
So how can i point to the new view using (V)Lisp?

Thanks
it is somehow related to my topic and manipulation with ViewCenter/X and ViewCenter/Y.
https://www.theswamp.org/index.php?topic=57407.msg611689#msg611689
Simple adjustments easily done with these lines:
Code: [Select]
(defun c:TEST (/ vp)
  (setq vp (entsel "\nSelect viewport to set view to 1.0, 1.0 point: "))
  (setpropertyvalue (car vp) "ViewCenter/X" 1.0)
  (setpropertyvalue (car vp) "ViewCenter/Y" 1.0)
  (princ)
)
This will set view to 1.0, 1.0 But there is more to consider, like ucs, twist, target and direction for viewport.

I don't think this will work how you describe. Viewport don't know what was copied.
Logic should be more like this:
1. Create new viewport
2. Jump to model and select vector, from which point to which point view needs to be updated (vector of your copied object).
3. Back to layout and update ViewCenter/X/Y of viewport
kruuger
« Last Edit: October 12, 2022, 05:42:21 PM by kruuger »

CADwiesel

  • Newt
  • Posts: 46
  • Wir machen das Mögliche unmöglich
Re: Copy viewport and linked Objects
« Reply #3 on: October 18, 2022, 05:35:53 AM »
Thanks for sharing the code, ribarm!

that's true, kruuger...
Code: [Select]
(setq vec (mapcar '- p2 p1))
(setq vs (getvar 'viewsize))
(setq vc (getvar 'viewctr))
(setq nvpt (mapcar '+ vc vec))
(vlax-invoke-method (vlax-get-acad-object) 'zoomcenter (vlax-3d-point nvpt) vs)
This code is working fine for vports, which have a view from top or front to that copied object.
But if you want to have a view from eg, left or right side of an (3D)Object you need to calculate the vector on a different way.
don't know yet how  :idiot2:
Gruß
CADwiesel
Besucht uns im CHAT

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: Copy viewport and linked Objects
« Reply #4 on: October 18, 2022, 06:11:20 AM »
Thanks for sharing the code, ribarm!

that's true, kruuger...
Code: [Select]
(setq vec (mapcar '- p2 p1))
(setq vs (getvar 'viewsize))
(setq vc (getvar 'viewctr))
(setq nvpt (mapcar '+ vc vec))
(vlax-invoke-method (vlax-get-acad-object) 'zoomcenter (vlax-3d-point nvpt) vs)
This code is working fine for vports, which have a view from top or front to that copied object.
But if you want to have a view from eg, left or right side of an (3D)Object you need to calculate the vector on a different way.
don't know yet how  :idiot2:

@CADwiesel

I've looked at my post and see no real reasons for not working in any view/ucs formation in 3D... If you have problems ab this task from your point of view, I'd try to something fix like relation I suppose Visual Lisp function should operate by default - (vlax-3d-point) variant requirement of 3D WCS point list... So, experimental proposal : (vlax-3d-point (trans (mapcar (function +) (trans vc 1 0) (trans vec 1 0 t)) 0 1))
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube