Jump to content

Axonometric Projection: Obtaining View Point Location in AutoCAD Model Space


Recommended Posts

Posted (edited)

The strip down version or short version of lisp routine of previous post with notes and error trapper removal

 

Phh

 

;;---------------------------------------------------------;;
;; Compute "Dr" based on AutoCAD system variable "VIEWDIR" ;;
;; By Phh 4/24/2022                                        ;;
;;---------------------------------------------------------;;
(vl-load-com)
(defun c:drc (/ pt0 pt1 ptx pty ptz hxLs hyRs hzCs Lr Rr Cr n Drvar)
  (setq pt1 (getvar "VIEWDIR"))
  (setq n (apply '+ (mapcar 'abs pt1)))
  (if (or (> (- n (fix n)) 0) (= n 3.0))
    (progn
      (setq pt0 '(0 0 0))
      (setq ptx '(1 0 0))
      (setq pty '(0 1 0))
      (setq ptz '(0 0 1))
      (setq hxLs (/ (* 2 (area3pts (list pt0 pt1 ptx))) (distance pt0 pt1)))      
      (setq hyRs (/ (* 2 (area3pts (list pt0 pt1 pty))) (distance pt0 pt1)))
      (setq hzCs (/ (* 2 (area3pts (list pt0 pt1 ptz))) (distance pt0 pt1)))
      (setq Lr (/ hxLs (max hxLs hyRs hzCs)))
      (setq Rr (/ hyRs (max hxLs hyRs hzCs)))
      (setq Cr (/ hzCs (max hxLs hyRs hzCs)))
      (setq Drvar (sqrt (* 0.5 (+ (* Lr Lr) (* Cr Cr) (* Rr Rr)))))
      (princ Drvar)
      (princ)
    )
  )
  (princ)
)
(defun area3pts (list3pts / a b c theArea)
  (setq a (distance (car  list3pts) (cadr  list3pts)))
  (setq b (distance (car  list3pts) (caddr list3pts)))
  (setq c (distance (cadr list3pts) (caddr list3pts)))
  (setq theArea (* 0.25 (sqrt (* (+ a b c) (+ (* -1 a) b c) (+ a (* -1 b) c)
                                 (+ a b (* -1 c))))))
)

 

Edited by phuynh
  • 3 months later...
  • Replies 24
  • Created
  • Last Reply

Top Posters In This Topic

  • phuynh

    19

  • marko_ribar

    3

  • lrm

    2

  • mhupp

    1

Top Posters In This Topic

Posted Images

Posted (edited)

New AxoCalcs.xlsx

 

Added position, location parameters
Added Variables:
Xa = Angle from X Axis
XYp = Angle from XY plan
for computing alternative viewpoint command using rotations instead of entering 3d point.

 

Detail of attached file
Excel version 2007, file is read only (extension .xlsx or .zip)
No macro used, worksheets protected but password not set to prevent accidental editing
Variable name scope per worksheet, except position & location parameter names are per workbook
Added various input validations, hide various rows and columns for cleaner look.

 

What this Excel does is calculate the viewpoint express in XYZ coordinates based on scale ratio inputs or inclination angle inputs and concatenate into AutoCAD command so can be used to paste to AutoCAD's prompt.


Calculation precision at minimum 8 digits, tested in AutoCAD at maximum 8 digits display,
(I would say at least between 13 to 15 decimal digits precision).

 

I would claim 1/3 of credit for my study, create this Excel spreadsheet and added some variables,
the other 2/3 belong to Dave Barber for his formulas.

 

Drop me a line tell me what you think, or what I need to improve!

 

Cheer!

 

 

Phh

 

 

AxoCalcs.PNG

AxoCalcs.xlsx

AxoCalcs.zip

Edited by phuynh
Posted (edited)

Params tab (Excel worksheet from previous post)

flatshot with "Dr" scaling and ... see below

and AxoCalcs.dwg

 

Phh

 

;;-----------------------------------------------------------------------;;
;; fsa.lsp (flatshot axonometric.. couldn't come up with good name)      ;;
;; By Phh 4/14/2022                                                      ;;
;;                                                                       ;;
;; Lisp to create 2D drawing from 3D solid model using flatshot command  ;;
;; Scaling entities in block necessary to match current AutoCAD unit.    ;;
;; Also change various properties after flatshot create block.           ;;
;;                                                                       ;;
;; Downside Note:                                                        ;;
;; When flatshot dialog come up - if Obscured lines checked, the         ;;
;; Linetype dropbox below must be selected "HIDDEN".                     ;;
;; For complex solid model with obcured lines enable, it takes abit      ;;
;; long to finish due to scaling if current view is axonometric view.    ;;
;; Can't find way to run script silent due to nature of flatshot command ;;
;;                                                                       ;;
;; Thanks cadtutor forum users for help & tips                           ;;
;;-----------------------------------------------------------------------;;

(defun c:fsa (/          ss
              ltsc       scfactor
              basept     blk
              eo         doc
              blocks     bcol
              sc         old_cmdecho
              old_osmode old_color
              old_lweight
              blkOrigin
             )

  (vl-load-com)

  ;;Start error traperr & save vars.
  (setq temperr *error*)
  (setq *error* traperr)
  (setq old_cmdecho (getvar "CMDECHO"))
  (setq old_osmode (getvar "OSMODE"))
  (setq old_color (getvar "CECOLOR"))
  (setq old_lweight (getvar "CELWEIGHT"))

  ;;Load hidden line if not
  (if (not (tblsearch "ltype" "HIDDEN"))
    (vl-cmdf "_.-LINETYPE" "_L" "HIDDEN" "acad.lin" "")
  )

  ;;Create layer name 251 to hold obcured lines
  (if (not (tblsearch "layer" "251"))
    (vl-cmdf "layer" "n" "251" "C" "251" "251" "LW" "0.09" "251" "LT" "HIDDEN"
             "251" "ON" "251" "")
  )

  (if
    (and
      ;;Set custom linetype scale for best appearance default is 1.0
      (setq ltsc "0.375")

      (setq scfactor (fs:drc))
      (setq basept (vlax-3d-point 0 0 0))
      (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))

      (setvar "OSMODE" 0)
      (setvar "CMDECHO" 0)

      (vl-cmdf "_.FLATSHOT" '(0.0 0.0 0.0) "" "" "")

      (setvar "CMDECHO" old_cmdecho)
      (setvar "OSMODE" old_osmode)

      (setq ss (ssget "L"))
      (setq ss (vla-get-ActiveSelectionSet doc))
    )

     (progn
       (vlax-for eo ss
         (if (vlax-property-available-p eo 'LinetypeScale t)
           (vla-put-LinetypeScale eo ltsc)
         )
         (if (eq (vla-get-Linetype eo) "HIDDEN")
           (vla-put-Layer eo "251")
         )
         (if
           (and (eq (vla-get-ObjectName eo) "AcDbBlockReference")
                (not (vl-position (vla-get-EffectiveName eo) blocks))
           )
            (setq blocks (cons (vla-get-EffectiveName eo) blocks))
         )
       )

       (setq bcol (vla-get-Blocks doc))
       (foreach blk blocks
         (vlax-for eo (vla-Item bcol blk)
           (if (/= scfactor 1.0)
             (vla-ScaleEntity eo basept scfactor)
           )
           (if (vlax-property-available-p eo 'LinetypeScale t)
             (vla-put-LinetypeScale eo ltsc)
           )
           (if (vlax-property-available-p eo 'Color t)
             (vla-put-color eo "256")
           )
           (if (vlax-property-available-p eo 'Lineweight t)
             (vla-put-LineWeight eo "-1")
           )
           (if (eq (vla-get-Linetype eo) "HIDDEN")
             (vla-put-Layer eo "251")
           )
         )
       )
       (vla-Regen (vla-get-ActiveDocument (vlax-get-acad-object))
                  acActiveViewport
       )
     )
  )
  (princ)
)

;;-----------------------------------------------------------------;;
;; Compute "Dr" based on AutoCAD current system variable "VIEWDIR" ;;
;; By Phh 4/14/2022                                                ;;
;;-----------------------------------------------------------------;;
(defun fs:drc (/ pt0 pt1 ptx pty ptz hxLs hyRs hzCs Lr Rr Cr n Drvar)
  (setq pt1 (getvar "VIEWDIR"))
  (setq n (apply '+ (mapcar 'abs pt1)))
  (if (or (> (- n (fix n)) 0) (= n 3.0))
    (progn
      (setq pt0 '(0 0 0))
      (setq ptx '(1 0 0))
      (setq pty '(0 1 0))
      (setq ptz '(0 0 1))
      (setq hxLs (/ (* 2 (area3pts (list pt0 pt1 ptx))) (distance pt0 pt1)))
      (setq hyRs (/ (* 2 (area3pts (list pt0 pt1 pty))) (distance pt0 pt1)))
      (setq hzCs (/ (* 2 (area3pts (list pt0 pt1 ptz))) (distance pt0 pt1)))
      (setq Lr (/ hxLs (max hxLs hyRs hzCs)))
      (setq Rr (/ hyRs (max hxLs hyRs hzCs)))
      (setq Cr (/ hzCs (max hxLs hyRs hzCs)))
      (setq Drvar (sqrt (* 0.5 (+ (* Lr Lr) (* Cr Cr) (* Rr Rr)))))
    )
    (progn
      (setq Drvar "1.0")
    )
  )
  (princ Drvar)
)

(defun area3pts (list3pts / a b c theArea)
  (setq a (distance (car list3pts) (cadr list3pts)))
  (setq b (distance (car list3pts) (caddr list3pts)))
  (setq c (distance (cadr list3pts) (caddr list3pts)))
  (setq theArea (* 0.25
                   (sqrt (* (+ a b c)
                            (+ (* -1 a) b c)
                            (+ a (* -1 b) c)
                            (+ a b (* -1 c))
                         )
                   )
                )
  )
)

;;----------------------------------------------;;
;; Error traper function restore save variables ;;
;;----------------------------------------------;;
(defun traperr (errmsg)
  (setvar "CMDECHO" old_cmdecho)
  (setvar "OSMODE" old_osmode)
  (setvar "CECOLOR" old_color)
  (setvar "CELWEIGHT" old_lweight)
  (setq *error* temperr)
  (prompt "\Resetting system variables ")
  (princ)
)

 

Params.PNG

AxoCalcs.dwg

Edited by phuynh
  • 1 year later...
Posted (edited)

Experiment - Excel functions (No VBA/macros)

 

Sorry, I am still newbie but manage to complile these two functions for computing axonometric viewpoint based on this thread, let me know if I need to improve. Since these Excel "LAMBDA" functions a bit long so I may split into 2 posts.

 

First,

Excel Lambda Function - Axonometric Inclination Angles

 

AxoIncl(LeftInclination,RightInclination,[Position],[Location])

 

Return - View point in X,Y,Z coordinates,(or rotation & angles), creates AutoCAD command for copy & paste onto AutoCAD prompt.

 

Optional parameters

[Position] :

positive number =  1 = (or any positive number) view point above horizon
negative number = -1 = (or any negative number) view point below horizon
(Note: enter 0 will cause input error!)
(Default, if not specify = 1 = above horizon)

 

[Location] :

Quadrant - valid entry are 1, 2, 3, 4, a view point location relative to WCS
(Any other than above numbers will reset to default 4)
(Default, if not specify = quadrant 4 = view from SE)

 

Input Notes:

Each of the inclination inputs should be between 0 and 90 degrees, and their sum should be less than 90 degrees, and Position must not equal to 0.

 

=LAMBDA(LeftInclination,RightInclination,[Position],[Location],
 LET(pos,IF(ISOMITTED(Position),1,SIGN(Position)),
     loc,IF(ISOMITTED(Location),4,IF(AND(Location>0,Location<5),INT(Location),4)),
     tbq,{1,1,1;2,-1,1;3,-1,-1;4,1,-1},
     Li,RADIANS(LeftInclination),
     Ri,RADIANS(RightInclination),
     Ci,Pi()/2-(Li+Ri),
     Lt,TAN(Li),
     Ct,TAN(Ci),
     Rt,TAN(Ri),
     Ls,SQRT(1-Ct*Lt),
     Cs,SQRT(1-Rt*Lt),
     Rs,SQRT(1-Rt*Ct),
     Lr,Ls*Ls/(MAX(Ls*Ls,Ls*Cs,Ls*Rs)),
     Cr,Ls*Cs/(MAX(Ls*Ls,Ls*Cs,Ls*Rs)),
     Rr,Ls*Rs/(MAX(Ls*Ls,Ls*Cs,Ls*Rs)),
     Dr,SQRT(0.5*(Lr^2+Cr^2+Rr^2)),
     Lu,1-(Ls^2),
     Cu,1-(Cs^2),
     Ru,1-(Rs^2),
     La,(PI()/2)-Ri,
     Ca,Li+Ri,
     Ra,(PI()/2)-Li,
     Ll,(SIN(La)*(MAX(Lr,Cr,Rr)/SIN(MIN(La,Ca,Ra))))/Lr,
     Cl,(SIN(Ca)*(MAX(Lr,Cr,Rr)/SIN(MIN(La,Ca,Ra))))/Cr,
     Rl,(SIN(Ra)*(MAX(Lr,Cr,Rr)/SIN(MIN(La,Ca,Ra))))/Rr,
     Xc,IF(Lr>Rr,(VLOOKUP(loc,tbq,2,FALSE)*IF(ISEVEN(loc),MIN(Ll,Rl),MAX(Ll,Rl))),(VLOOKUP(loc,tbq,2,FALSE)*IF(ISEVEN(loc),MAX(Ll,Rl),MIN(Ll,Rl)))),
     Yc,IF(Lr>Rr,(VLOOKUP(loc,tbq,3,FALSE)*IF(ISEVEN(loc),MAX(Ll,Rl),MIN(Ll,Rl))),(VLOOKUP(loc,tbq,3,FALSE)*IF(ISEVEN(loc),MIN(Ll,Rl),MAX(Ll,Rl)))),
     Zc,Cl*pos,
     Xa,ATAN2(Xc,Yc),
     XYp,ATAN(Zc/SQRT(Xc^2+Yc^2)),
     VptRotate,DEGREES(Xa),
     VptAngXYp,DEGREES(XYp),
     \0,"Note: Check for input error and create AutoCAD command for copy & paste to AutoCAD prompt.",
     IF(AND(Li<(0.5*PI()),Ri<(0.5*PI()),SUM(Li,Ri)<(0.5*PI()),NOT(pos=0)),

        ("(command  ""_.OSMODE"" ""0"" ""_.VPOINT"" ""_R"" "&VptRotate&" "&VptAngXYp&" ""_.FLATSHOT"" ""0,0,0"" """" """" """" ""_.SCALE"" ""_L"" """" ""0,0,0"" "&Dr&")"),

        "Inclination angle or view position input error!"
       )
    )
)

 

 

9/23/2024

 

Note:

I realized that there is no need to have these 3 intermediate variables Lu, Ru, Cu in this function and they can be removed, but no harm to have them there.

 

The Lu, Ru & Cu intermediate variables used for obtaining Li, Ri & Ci (the inclination angles) which they already supplied when the function calls.

 

Phh

 

Edited by phuynh
Posted (edited)

Second,

Excel Lambda Function - Axonometric Scale Ratios

 

AxoSclr(Lr,Cr,Rr,[Position],[Location])

 

Return - View point in X,Y,Z coordinates,(or rotation & angles), creates AutoCAD command for copy & paste onto AutoCAD prompt.

 

Optional parameters
[Position] :

positive number =  1 = (or any positive number) view point above horizon
negative number = -1 = (or any negative number) view point below horizon
(Note: enter 0 will cause input error)
(Default, if not specify = 1 = above horizon)

 

[Location] :

Quadrant - valid entry are 1, 2, 3, 4, a view point location relative to WCS
(Any other than above numbers will reset to default 4)
(Default, if not specify = quadrant 4 = view from SE)

 

Input Notes: Scale ratio inputs should be greater than 0, and the square of one ratio should not exceed the sum of the squares of the other two ratios, and Position must not equal to 0.

 

=LAMBDA(Lr,Cr,Rr,[Position],[Location],
 LET(pos,IF(ISOMITTED(Position),1,SIGN(Position)),
     loc,IF(ISOMITTED(Location),4,IF(AND(Location>0,Location<5),INT(Location),4)),
     tbq,{1,1,1;2,-1,1;3,-1,-1;4,1,-1},
     Dr,SQRT(0.5*(Lr^2+Cr^2+Rr^2)),
     Ls,Lr/Dr,
     Cs,Cr/Dr,
     Rs,Rr/Dr,
     Lu,1-(Ls^2),
     Cu,1-(Cs^2),
     Ru,1-(Rs^2),
     Li,ATAN(SQRT(Lu*Cu/Ru)),
     Ci,ATAN(SQRT(Lu*Ru/Cu)),
     Ri,ATAN(SQRT(Ru*Cu/Lu)),
     Lt,TAN(Li),
     Ct,TAN(Ci),
     Rt,TAN(Ri),
     La,(PI()/2)-Ri,
     Ca,Li+Ri,
     Ra,(PI()/2)-Li,
     Ll,(SIN(La)*(MAX(Lr,Cr,Rr)/SIN(MIN(La,Ca,Ra))))/Lr,
     Cl,(SIN(Ca)*(MAX(Lr,Cr,Rr)/SIN(MIN(La,Ca,Ra))))/Cr,
     Rl,(SIN(Ra)*(MAX(Lr,Cr,Rr)/SIN(MIN(La,Ca,Ra))))/Rr,
     Xc,IF(Lr>Rr,(VLOOKUP(loc,tbq,2,FALSE)*IF(ISEVEN(loc),MIN(Ll,Rl),MAX(Ll,Rl))),(VLOOKUP(loc,tbq,2,FALSE)*IF(ISEVEN(loc),MAX(Ll,Rl),MIN(Ll,Rl)))),
     Yc,IF(Lr>Rr,(VLOOKUP(loc,tbq,3,FALSE)*IF(ISEVEN(loc),MAX(Ll,Rl),MIN(Ll,Rl))),(VLOOKUP(loc,tbq,3,FALSE)*IF(ISEVEN(loc),MIN(Ll,Rl),MAX(Ll,Rl)))),
     Zc,Cl*pos,
     Xa,ATAN2(Xc,Yc),
     XYp,ATAN(Zc/SQRT(Xc^2+Yc^2)),
     VptRotate,DEGREES(Xa),
     VptAngXYp,DEGREES(XYp),
     \0,"Note: Check for input error and create AutoCAD command for copy & paste to AutoCAD prompt.",
     IF(AND(Lr^2<(Cr^2+Rr^2),Cr^2<(Rr^2+Lr^2),Rr^2<(Cr^2+Lr^2),NOT(pos=0)),

        ("(command  ""_.OSMODE"" ""0"" ""_.VPOINT"" ""_R"" "&VptRotate&" "&VptAngXYp&" ""_.FLATSHOT"" ""0,0,0"" """" """" """" ""_.SCALE"" ""_L"" """" ""0,0,0"" "&Dr&")"),

        "Scale ratio or view position input error!"
       )
    )
)

 

Phh

 

Edited by phuynh

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...