TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Lupo76 on August 27, 2015, 02:38:07 AM

Title: Rotate UCS into viewport
Post by: Lupo76 on August 27, 2015, 02:38:07 AM
How can I set the UCS Global viewport, without going into it?

Do you have any suggestions?
Title: Re: Rotate UCS into viewport
Post by: roy_043 on August 27, 2015, 10:45:33 AM
Changing a viewport through (entmod) is problematic. For example changing 'VP Freeze' layers (Xdata) is not possible with (entmod). In the past I have reported this as a BricsCAD bug to the Bricsys team but was told that AutoCAD has the same issue and therefore this behavior was compatible...

To change the 'VP Freeze' layers a Visual Lisp approach will work. But, to my knowledge,  there are no VL properties or methods for the viewport UCS.

The code below does NOT work on BricsCAD.
Code - Auto/Visual Lisp: [Select]
  1. (defun VP_To_WCS (enme / elst)
  2.   (setq elst (entget enme))
  3.   (entmod
  4.     (subst
  5.       '(110 0.0 0.0 0.0) ; UCS origin.
  6.       (assoc 110 elst)
  7.       (subst
  8.         '(111 1.0 0.0 0.0) ; UCS X-axis.
  9.         (assoc 111 elst)
  10.         (subst
  11.           '(112 0.0 1.0 0.0) ; UCS Y-axis.
  12.           (assoc 112 elst)
  13.           elst
  14.         )
  15.       )
  16.     )
  17.   )
  18. )
Title: Re: Rotate UCS into viewport
Post by: Lee Mac on August 27, 2015, 10:52:18 AM
Changing a viewport through (entmod) is problematic.

From the AutoCAD Developer Docs (http://docs.autodesk.com/ACD/2013/ENU/index.html?url=files/GUID-C7D27797-247E-49B9-937C-0D8C58F4C832.htm,topicNumber=d30e612442) on entmod:
Quote
There are restrictions on the changes the entmod function can make:
  • An entity's type and handle cannot be changed. If you want to do this, use entdel to delete the entity, and then make a new entity with the command or entmake function.
  • The entmod function cannot change internal fields, such as the entity name in the -2 group of a seqend entity. Attempts to change such fields are ignored.
  • You cannot use the entmod function to modify a viewport entity.
Title: Re: Rotate UCS into viewport
Post by: roy_043 on August 27, 2015, 01:19:07 PM
Thank you Lee. Strange restriction though.
Title: Re: Rotate UCS into viewport
Post by: pedroantonio on August 27, 2015, 01:36:36 PM
I use this lisp code is perfect !!

Code - Auto/Visual Lisp: [Select]
  1.  
  2. ; DVA.LSP
  3.  
  4. ; Jim Nakazawa
  5. ; (415) 768-1234
  6.  
  7. ; TO SET DVIEW TWIST ANGLE BY POINTING TO AN EXISTING LINE
  8. ; FIRST DRAW THE LINE FROM LEFT TO RIGHT THAT YOU WANT TO SET THE DVIEW
  9. ; TWIST ANGLE FROM
  10.  
  11. (defun C:DVA (/ rgm a b pt1 pt2 ang1 )
  12.   (setq rgm (getvar "regenmode"))
  13.   (command "setvar" "regenmode" 0)
  14.   (setq a (entsel "Select a line to set the orientation DVIEW TWist: "))
  15.   (setq b (entget (car a)))
  16.   (setq pt1 (cdr (assoc 10 b)))
  17.   (setq pt2 (cdr (assoc 11 b)))
  18.   (setq ang1 (angle pt1 pt2))
  19.   (setq ang1 (/ (* ang1 200.0) pi))
  20.   (setq ang1 (- ang1))
  21.   (command "dview"  "" "tw" ang1 "")
  22.   (command "setvar" "regenmode" rgm)
  23.   (princ "Dview Twist Angle Set to ") (princ (+ 400.0 ang1)) (terpri)
  24. ;this should be modified to show angle in current angular units
  25.   (princ)
  26. ) ;this routine seems to work
  27.  
  28.  
Title: Re: Rotate UCS into viewport
Post by: roy_043 on August 28, 2015, 03:04:55 AM
I use this lisp code is perfect !!
This code changes the twist angle not the viewport UCS. Changing the twist angle can be done with Visual Lisp (without activating the viewport).
Title: Re: Rotate UCS into viewport
Post by: pedroantonio on August 28, 2015, 04:39:58 AM
This code changes the twist angle not the viewport UCS. Changing the twist angle can be done with Visual Lisp (without activating the viewport).

Yes roy_043 but this lisp  twist angle  only in the viewport not in the modelspace and this is important. 
Title: Re: Rotate UCS into viewport
Post by: roy_043 on August 28, 2015, 06:35:30 AM
@ Topographer: No doubt the code in your post can be useful, but it is not what the OP needs.
Title: Re: Rotate UCS into viewport
Post by: tombu on August 28, 2015, 10:45:22 AM
I use this lisp code is perfect !!

Code - Auto/Visual Lisp: [Select]
  1.  
  2. ; DVA.LSP
  3.  
  4. ; Jim Nakazawa
  5. ; (415) 768-1234
  6.  
  7. ; TO SET DVIEW TWIST ANGLE BY POINTING TO AN EXISTING LINE
  8. ; FIRST DRAW THE LINE FROM LEFT TO RIGHT THAT YOU WANT TO SET THE DVIEW
  9. ; TWIST ANGLE FROM
  10.  
  11. (defun C:DVA (/ rgm a b pt1 pt2 ang1 )
  12.   (setq rgm (getvar "regenmode"))
  13.   (command "setvar" "regenmode" 0)
  14.   (setq a (entsel "Select a line to set the orientation DVIEW TWist: "))
  15.   (setq b (entget (car a)))
  16.   (setq pt1 (cdr (assoc 10 b)))
  17.   (setq pt2 (cdr (assoc 11 b)))
  18.   (setq ang1 (angle pt1 pt2))
  19.   (setq ang1 (/ (* ang1 200.0) pi))
  20.   (setq ang1 (- ang1))
  21.   (command "dview"  "" "tw" ang1 "")
  22.   (command "setvar" "regenmode" rgm)
  23.   (setvar "snapang" (- (getvar "viewtwist")))
  24.   (princ "Dview Twist Angle Set to ") (princ (+ 400.0 ang1)) (terpri)
  25. ;this should be modified to show angle in current angular units
  26.   (princ)
  27. ) ;this routine seems to work
  28.  
  29.  
As a licensed Surveyor doing Civil work like Topographer I avoid changing the coordinate system.  I use a macro to twist views as needed that resets the crosshairs after DVIEW with
Code: [Select]
(setvar "snapang" (- (getvar "viewtwist"))).  Added it to your routine for my purposes.
Not exactly what Lupo76 asked for, but your solution could work for him.
Title: Re: Rotate UCS into viewport
Post by: roy_043 on August 28, 2015, 05:09:50 PM
Reading this topic will help to understand what the OP wants:
http://www.theswamp.org/index.php?topic=29231.0
Title: Re: Rotate UCS into viewport
Post by: Lupo76 on August 29, 2015, 02:47:51 AM
Thank you all!
I managed to solve my problem without rotating the UCS in the viewport, but thank you all for your concern
Title: Re: Rotate UCS into viewport
Post by: Kerry on August 29, 2015, 03:49:27 AM
Thank you all!
I managed to solve my problem without rotating the UCS in the viewport, but thank you all for your concern


That's great!
How did you do it ??

Title: Re: Rotate UCS into viewport
Post by: Lupo76 on August 29, 2015, 11:44:19 AM
That's great!
How did you do it ??

I just adopted a totally different system to do what I had to do.
Any explanation would be too long, and however OT
Title: Re: Rotate UCS into viewport
Post by: Kerry on August 29, 2015, 01:25:18 PM



That is really disappointing.


You come here and ask for help, ask for people to take time and effort to resolve a problem you have.
Then you excuse yourself for your lack of effort to explain how the issue was resolved, completely denying future readers of this thread the benefit of a solution you crafted.


 
Title: Re: Rotate UCS into viewport
Post by: Marc'Antonio Alessi on August 31, 2015, 04:08:09 AM
 :knuppel2: