Author Topic: need help to fix inconsistency with osmode  (Read 1193 times)

0 Members and 1 Guest are viewing this topic.

rhino

  • Guest
need help to fix inconsistency with osmode
« on: April 23, 2009, 01:35:53 PM »
Hi,

I wrote this routine to help me draw polylines with a user set width between two points and trim each side by 150mm - I use it to show mezz beams on a plan...

However there is an inconsistency with the way I use to pick the points 'osmode'; this pline wont be trimmed if the user selects 2 different types of osnaps... :?

Code: [Select]
;-------------------------------------------------------------------------------------------------------;
;  Mezz Pline - Utility to draw Mezz Beams CJC aka 'RHINO' 22/04/2009 ;
;-------------------------------------------------------------------------------------------------------;
; This routine draws the mezzanine beams plans   ;
;-------------------------------------------------------------------------------------------------------;

(defun c:mpl (/) (c:mezz_pline))
(defun c:mezz_pline (/ usercmd userosm userplw userlay plw mode pt1 pt2 cntr loop *error* )
(defun *error* (msg)
    (if (not
          (member msg '("console break" "Function cancelled" "quit / exit abort" "" nil))
        )
      (princ (strcat "\nError: " msg))
    )     
    (and usercmd (setvar "cmdecho" usercmd)
userosm (setvar "osmode" userosm)
userplw (setvar "plinewid" userplw)
userclr (setvar "cecolor" userclr)
userlay (setvar "clayer" userlay)
userort (setvar "orthomode" userort)
;usersnp (setvar "autosnap" usersnp)
        )
    (princ)
  ) ; end error function
 
; routine starts here
  (setq usercmd (getvar "cmdecho")
userosm (getvar  "osmode")
userplw (getvar "plinewid")
userclr (getvar "cecolor")
userlay (getvar "clayer")
userort (getvar "orthomode")
;usersnp (getvar "autosnap")
)
  (setvar "cmdecho"  0)
  ;(setvar "autosnap" 0)
  (setvar "orthomode" 1)
  (prompt "\nThis command will draw mezzanine beams (thick polylines) between 2 points...
   \nPlease select points [Left to Right for X] & [Top to Bottom for Y]..."
)
  (setq plw (getint "\nEnter Pline Thickness <60>: "))
    (or plw (setq plw 60))
    (setvar "plinewid" plw)
    (command "_-layer" "m" "STEEL" "ltype" "continuous" "" "lweight" "0.000" "" "color" "3" "" ""
     "_-color" 4
);force layer to "STEEL" & set color to cyan (4)
      (setq loop "T")
      (while (= loop "T")
(setvar "osmode" 147)
   (setq pt1 (getpoint "\nFirst point..."))
     (if pt1 (setq loop "T"))
      (if (null pt1) ((exit) (princ)));if no pt1 selected - exit quietly :)
(if (= loop "T") (setq pt2 (getpoint pt1 "Second point...")))
(if (= (cadr pt1) (cadr pt2))
  (progn
    (setq pt1 (list (+ (car pt1) 150) (cadr pt1))
  pt2 (list (- (car pt2) 150) (cadr pt1))
)
  )
);end if trim x
(if (= (car pt1) (car pt2))
  (progn
    (setq pt1 (list (car pt1) (- (cadr pt1) 150))
  pt2 (list (car pt1) (+ (cadr pt2) 150))
)
  )
);end if trim y
(setvar "osmode" 0)
(command "._pline" pt1 pt2 "")
);end loop

  (*error* "")
  (princ)
)
  (prompt "\nmezz_pline is now available - type <MPL> to run! ")

help and solutions appreciated...
« Last Edit: April 23, 2009, 02:00:29 PM by rhino »

rhino

  • Guest
Re: need help to fix inconsistency with osmode
« Reply #1 on: April 23, 2009, 01:51:25 PM »
sorry...

this bit was missing with the original post - before the loop

(setq loop "T")

:D

rhino

  • Guest
Re: need help to fix inconsistency with osmode
« Reply #2 on: April 23, 2009, 11:28:19 PM »
problem solved...it was due to this system variable "OSNAPCOORD"

Code: [Select]
;-------------------------------------------------------------------------------------------------------;
;  Mezz Pline - Utility to draw Mezz Beams CJC aka 'RHINO' 22/04/2009 ;
;-------------------------------------------------------------------------------------------------------;
; This routine draws the mezzanine beams plans   ;
; - Fixed inconsistency when user picks 2 different Osnaps - 24/04/09
;-------------------------------------------------------------------------------------------------------;

(defun c:mpl (/) (c:mezz_pline))
(defun c:mezz_pline (/ usercmd userosm userplw userlay usersnp plw mode pt1 pt2 cntr loop *error* )
(defun *error* (msg)
    (if (not
          (member msg '("console break" "Function cancelled" "quit / exit abort" "" nil))
        )
      (princ (strcat "\nError: " msg))
    )     
    (and usercmd (setvar "cmdecho" usercmd)
userosm (setvar "osmode" userosm)
userplw (setvar "plinewid" userplw)
userclr (setvar "cecolor" userclr)
userlay (setvar "clayer" userlay)
userort (setvar "orthomode" userort)
usersnp (setvar "osnapcoord" usersnp)
        )
    (princ)
  ) ; end error function
 
; routine starts here
  (setq usercmd (getvar "cmdecho")
userosm (getvar  "osmode")
userplw (getvar "plinewid")
userclr (getvar "cecolor")
userlay (getvar "clayer")
userort (getvar "orthomode")
[color=red]usersnp (getvar "osnapcoord")[/color]
)
  (setvar "cmdecho"  0)
  [color=red](setvar "osnapcoord" 1)[/color]
  (setvar "orthomode" 1)

  (prompt "\nThis command will draw mezzanine beams (thick polylines) between 2 points...
   \nPlease select points [Left to Right for X] & [Top to Bottom for Y]..."
)
  (setq plw (getint "\nEnter Pline Thickness <60>: "))
    (or plw (setq plw 60))
    (setvar "plinewid" plw)
    (command "_-layer" "m" "STEEL" "ltype" "continuous" "" "lweight" "0.000" "" "color" "3" "" ""
     "_-color" 4
);force layer to "STEEL" & set color to cyan (4)
      (setq loop "T")
      (while (= loop "T")
(setvar "osmode" 147)
   (setq pt1 (getpoint "\nFirst point..."))
     (if pt1 (setq loop "T"))
      (if (null pt1) ((exit) (princ)));if no pt1 selected - exit quietly :)
(if (= loop "T") (setq pt2 (getpoint pt1 "Second point...")))
(if (= (cadr pt1) (cadr pt2))
  (progn
    (setq pt1 (list (+ (car pt1) 150) (cadr pt1))
  pt2 (list (- (car pt2) 150) (cadr pt2))
)
  )
);end if trim x
(if (= (car pt1) (car pt2))
  (progn
    (setq pt1 (list (car pt1) (- (cadr pt1) 150))
  pt2 (list (car pt2) (+ (cadr pt2) 150))
)
  )
);end if trim y
(setvar "osmode" 0)
(command "._pline" pt1 pt2 "")
);end loop

  (*error* "")
  (princ)
)
  (prompt "\nmezz_pline is now available - type <MPL> to run! ")