ksperopoulos Posted March 25, 2016 Posted March 25, 2016 I am beating my head up against the wall trying to figure this out! If anyone can give me some insight, I would greatly appreciate it. While on a layout tab, I could have one of 3 different UCS scenarios. One may be "World" UCS, one might be a named UCS, and the last might be an unnamed UCS. After I retrieve information about the current paperspace UCS, I activate the floating viewport and apply the same UCS that I set in paperspace to the view in modelspace. (I have this working with the exception of an unnamed UCS.) Then, while the floating viewport is still activated, I will run the DIMLINEAR command. I get the two points for the ends of my dimension, but when I deactivate the floating viewport and try to place the dimension, it is way off in timbuktu. Can anyone please point out my mistake that is in this first part of my if function? (setq space (vla-get-ActiveSpace doc)) (if (= space 0) (progn (setq oldmspace (vla-get-MSpace doc) oldecho (vlax-variant-value (vla-GetVariable doc "cmdecho")) oldosnaps (vlax-variant-value (vla-GetVariable doc "osmode")) olddassoc (vlax-variant-value (vla-GetVariable doc "dimassoc")) currtab (vlax-variant-value (vla-GetVariable doc "ctab")) currvp (vlax-variant-value (vla-GetVariable doc "cvport")) count (sslength (ssget "_x" (list '(0 . "VIEWPORT") (cons 410 currtab)))) ) (vla-SetVariable doc "dimassoc" 1) (if (> count 2) (if (= currvp 1) (progn (setq psename (ssname (ssget "_x" (list '(0 . "VIEWPORT") (cons 410 currtab) (cons 69 currvp))) 0) pselist (entget psename) ucso (cdr (assoc 110 pselist)) ucsx (cdr (assoc 111 pselist)) ucsy (cdr (assoc 112 pselist)) named (cdr (assoc 345 pselist)) world (and (equal ucso '(0 0 0)) (equal ucsx '(1 0 0)) (equal ucsy '(0 1 0))) ucsn (if (null world) (if (null named) (command "_ucs" "_na" "_s" "TempUCS") (cdr (assoc 2 (entget named))) ) "" ) vpename (car (entsel "\nSelect a viewport to activate: ")) vpelist (entget vpename) vptwang (atof (angtos (cdr (assoc 51 vpelist)) 0)) vpnumb (cdr (assoc 69 vpelist)) vpobj (vlax-ename->vla-object vpename) vpscale (vla-get-CustomScale vpobj) dimscale (/ 1 vpscale) ) (if (= (vla-get-DisplayLocked vpobj) :vlax-false) (vla-put-DisplayLocked vpobj :vlax-true) ) (vla-put-MSpace doc :vlax-true) (vla-SetVariable doc "cvport" vpnumb) (vla-SetVariable doc "cmdecho" 0) (if (= ucsn "") (command "_ucs" "_v") (command "_ucs" "_na" "_r" ucsn) ) (while (setq point1 (getpoint "\nSpecify first extension line origin or <Exit>: ")) (if (= vpnumb (vlax-variant-value (vla-GetVariable doc "cvport"))) (progn (setq point2 (getpoint point1 "\nSpecify second extension line origin or <Exit>: ") trans1 (if (null world) (trans (trans point1 1 2) 2 3) (trans (trans point1 0 2) 2 3) ) trans2 (if (null world) (trans (trans point2 1 2) 2 3) (trans (trans point2 0 2) 2 3) ) ) (vla-put-MSpace doc :vlax-false) (vla-SetVariable doc "DIMLFAC" dimscale) (vla-SetVariable doc "osmode" 16384) (command "DIMLINEAR" trans1 trans2 (progn (vla-SetVariable doc "osmode" oldosnaps) (prompt "Specify dimension line location: ") pause ) ) (if (= ucsn "TempUCS") (command "_ucs" "_na" "_d" "TempUCS") ) (vla-put-MSpace doc :vlax-true) ) (prompt "\nCommand can only be used on one viewport at a time. \nInvalid point input. ") ) ) (vla-put-MSpace doc oldmspace) (vla-SetVariable doc "cmdecho" oldecho) (vla-SetVariable doc "osmode" oldosnaps) (vla-SetVariable doc "dimassoc" olddassoc) (vla-SetVariable doc "clayer" oldlay) (vla-put-ActiveDimStyle doc olddim) ) Quote
devitg Posted March 25, 2016 Posted March 25, 2016 As far as I can follow you , I put some remarks on it Do you use the VLIDE LIsp Editor ??? (SETQ acad-obj (VLAX-GET-ACAD-OBJECT)) (SETQ doc (VLA-GET-ACTIVEDOCUMENT acad-obj)) (setq space (vla-get-ActiveSpace doc)) ;_ doc is not defined ;; you can use (setq space (Getvar "tilemode" )) (if (= space 0);_ not closed (progn ;_ not closed (setq oldmspace (vla-get-MSpace doc) oldecho (vlax-variant-value (vla-GetVariable doc "cmdecho")) oldosnaps (vlax-variant-value (vla-GetVariable doc "osmode")) olddassoc (vlax-variant-value (vla-GetVariable doc "dimassoc")) currtab (vlax-variant-value (vla-GetVariable doc "ctab")) currvp (vlax-variant-value (vla-GetVariable doc "cvport")) count (sslength (ssget "_x" (list '(0 . "VIEWPORT") (cons 410 currtab)))) ; setq end. NOT CLOSED ;end progn NOT CLOSED IDEM ; end if IDEM (vla-SetVariable doc "dimassoc" 1) (if (> count 2) ;;;;IT IS NOT CLOSED BY A MATCHING PARENTESIS (if (= currvp 1);;;;IT IS NOT CLOSED BY A MATCHING PARENTESIS (progn (setq psename (ssname (ssget "_x" (list '(0 . "VIEWPORT") (cons 410 currtab) (cons 69 currvp))) 0) pselist (entget psename) ucso (cdr (assoc 110 pselist)) ucsx (cdr (assoc 111 pselist)) ucsy (cdr (assoc 112 pselist)) named (cdr (assoc 345 pselist)) world (and (equal ucso '(0 0 0)) (equal ucsx '(1 0 0)) (equal ucsy '(0 1 0))) ucsn (if (null world) (if (null named) (command "_ucs" "_na" "_s" "TempUCS") (cdr (assoc 2 (entget named))) ) "" ) vpename (car (entsel "\nSelect a viewport to activate: ")) vpelist (entget vpename) vptwang (atof (angtos (cdr (assoc 51 vpelist)) 0)) vpnumb (cdr (assoc 69 vpelist)) vpobj (vlax-ename->vla-object vpename) vpscale (vla-get-CustomScale vpobj) dimscale (/ 1 vpscale) );; IT SETQ IS CLOSED (if (= (vla-get-DisplayLocked vpobj) :vlax-false) (vla-put-DisplayLocked vpobj :vlax-true) );; IT IF IS CLOSED (vla-put-MSpace doc :vlax-true) (vla-SetVariable doc "cvport" vpnumb) (vla-SetVariable doc "cmdecho" 0) (if (= ucsn "") (command "_ucs" "_v") (command "_ucs" "_na" "_r" ucsn) );; IT IF IS CLOSED (while (setq point1 (getpoint "\nSpecify first extension line origin or <Exit>: ")) (if (= vpnumb (vlax-variant-value (vla-GetVariable doc "cvport"))) (progn (setq point2 (getpoint point1 "\nSpecify second extension line origin or <Exit>: ") trans1 (if (null world) (trans (trans point1 1 2) 2 3) (trans (trans point1 0 2) 2 3) ) trans2 (if (null world) (trans (trans point2 1 2) 2 3) (trans (trans point2 0 2) 2 3) ) ) (vla-put-MSpace doc :vlax-false) (vla-SetVariable doc "DIMLFAC" dimscale) (vla-SetVariable doc "osmode" 16384) (command "DIMLINEAR" trans1 trans2 (progn (vla-SetVariable doc "osmode" oldosnaps) (prompt "Specify dimension line location: ") pause ) ) (if (= ucsn "TempUCS") (command "_ucs" "_na" "_d" "TempUCS") ) (vla-put-MSpace doc :vlax-true) ) (prompt "\nCommand can only be used on one viewport at a time. \nInvalid point input. ") ) );; THIS WHILE IS CLOSED (vla-put-MSpace doc oldmspace) (vla-SetVariable doc "cmdecho" oldecho) (vla-SetVariable doc "osmode" oldosnaps) (vla-SetVariable doc "dimassoc" olddassoc) (vla-SetVariable doc "clayer" oldlay) (vla-put-ActiveDimStyle doc olddim) );__ it close the progn ;_ from here I do not follow the way you did it Quote
ksperopoulos Posted March 25, 2016 Author Posted March 25, 2016 Thank you for taking the time to look at my code devitg! I appreciate your comments. The code I have posted above is just a small part of a much larger lisp routine. The items you have commented on have already been taken care of in the rest of that code. I am testing this portion of the code. That is why I only posted this. I do not use VLIDE. I use Notepad++. I'm not really sure why I don't use VLIDE. I've always just been more of a notepad and notepad++ guy. Quote
devitg Posted March 26, 2016 Posted March 26, 2016 You ask if the IF is correct , as it is not closed , I find hard to check it . Despite you are a NOTEPAD and NOTEPAD++ guy , in my humble opinion, VLIDE is the best suited tool to make LISP. It can check for sintaxsys error , and more details to debug a LISP . Quote
cwake Posted March 26, 2016 Posted March 26, 2016 Hi Kyle, it's been a while... I won't lie, it's a bit difficult trying to understand the overall objective, but here's a few observations. The coordinate transformations that you are performing with (trans (trans point1 1 2) 2 3) and (trans (trans point1 0 2) 2 3) are returning coordinates in the Display Coordinate System of paperspace (DCS), which for simplicity is the World Coordinate System there. So that is why you would be creating a dimension "off in timbuktu" when you have a User Coordinate System set in paperspace at the time of creating the dimension (with command). If you are going to continue with the present approach of setting the same coordinate system in both modelspace and paperspace first, you would find that the coordinates returned by (trans (trans (trans point1 1 2) 2 3) 0 1) and (trans (trans (trans point1 0 2) 2 3) 0 1) would do what you want. A second alternative would be to use entmake or vla-AddDimRotated using the paperspace coordinates you are currently calculating. I can't help but wonder if it is really necessary to change the coordinate system in modelspace to do what you are trying to do. I'll leave that up to you, but it seems that just the one line of code (setq trans1 (trans (trans (getpoint) 1 2) 2 3)) should do all that is necessary to translate the selected point coordinate to one in paperspace, and then since you are switching back to paperspace prior to creating the dimension anyway, you could then use (trans trans1 0 1) after changing as the input to the command. None of that would require changing the UCS in modelspace. You also said that you haven't got the unnamed UCS application working. In the if statements for the setq that you have for symbol 'ucsn', you have (command "_ucs" "_na" "_s" "TempUCS"). This will return nil, not the string name of the temporary UCS. In which case, the later call to (command "_ucs" "_na" "_r" ucsn) will not be able to set the correct UCS in modelspace. I find the simplest way to find out information about the current coordinate system is to check the system variables, i.e. "UCSORG", "UCSXDIR" and "UCSYDIR". In your case where it appears that you are really only interested if the current UCS is World or not, you could just check if "WORLDUCS" is 0 or 1 and save several lines of code. For example, you could just use (setq world (= (getvar "WORLDUCS") 1)). I hope that can be helpful in some way. Cheers. Quote
ksperopoulos Posted March 28, 2016 Author Posted March 28, 2016 Thank you guys. I apologize if my abbreviated code is difficult to understand. I hesitate to post it all, but just to hopefully clarify a few things, here is the whole thing. (It's still very preliminary.) To try and make a long story short, here is what I am trying to accomplish: If a user is on a layout tab, and they want to place a dimension, the viewport's scale will be applied to the dimension's linear scale factor. This needs to be able to accommodate one or more viewports on a single layout tab; the UCS being set to world, named, or unnamed; and viewports that have or don't have a twist angle. The dimensions needs to be placed in paperspace. (And just so everyone is clear - using the DIMLINEAR command in paperspace with the system variable DIMASSOC set to 0, 1, or 2 does not work for me due to the objects we are dimensioning. It's a plug-in that AutoCAD does not read the same as native AutoCAD objects.) BTW - I know my variables in the first portion don't match up with other variables in the rest of the code. That is because I started to rethink how I wanted to attack this project. Therefore, that is why I only posted the portion of code I thought was relevant to my situation. I will try your suggestions Clint and see what I come up with. Thank you. (setq space (vla-get-ActiveSpace doc)) (if (= space 0) (progn (setq oldmspace (vla-get-MSpace doc) oldecho (vlax-variant-value (vla-GetVariable doc "cmdecho")) oldosnaps (vlax-variant-value (vla-GetVariable doc "osmode")) olddassoc (vlax-variant-value (vla-GetVariable doc "dimassoc")) currtab (vlax-variant-value (vla-GetVariable doc "ctab")) currvp (vlax-variant-value (vla-GetVariable doc "cvport")) count (sslength (ssget "_x" (list '(0 . "VIEWPORT") (cons 410 currtab)))) ) (vla-SetVariable doc "dimassoc" 1) (if (> count 2) (if (= currvp 1) (progn (setq psename (ssname (ssget "_x" (list '(0 . "VIEWPORT") (cons 410 currtab) (cons 69 currvp))) 0) pselist (entget psename) ucso (cdr (assoc 110 pselist)) ucsx (cdr (assoc 111 pselist)) ucsy (cdr (assoc 112 pselist)) named (cdr (assoc 345 pselist)) world (and (equal ucso '(0 0 0)) (equal ucsx '(1 0 0)) (equal ucsy '(0 1 0))) ucsn (if (null world) (if (null named) (command "_ucs" "_na" "_s" "TempUCS") (cdr (assoc 2 (entget named))) ) "" ) vpename (car (entsel "\nSelect a viewport to activate: ")) vpelist (entget vpename) vptwang (atof (angtos (cdr (assoc 51 vpelist)) 0)) vpnumb (cdr (assoc 69 vpelist)) vpobj (vlax-ename->vla-object vpename) vpscale (vla-get-CustomScale vpobj) dimscale (/ 1 vpscale) ) (if (= (vla-get-DisplayLocked vpobj) :vlax-false) (vla-put-DisplayLocked vpobj :vlax-true) ) (vla-put-MSpace doc :vlax-true) (vla-SetVariable doc "cvport" vpnumb) (vla-SetVariable doc "cmdecho" 0) (if (and (= ucsn "") (= vptwang 0)) (command "_ucs" "_w") (command "_ucs" "_na" "_r" ucsn) ) (while (setq point1 (getpoint "\nSpecify first extension line origin or <Exit>: ")) (if (= vpnumb (vlax-variant-value (vla-GetVariable doc "cvport"))) (progn (setq point2 (getpoint point1 "\nSpecify second extension line origin or <Exit>: ") trans1 (if (null world) (trans (trans point1 1 2) 2 3) (trans (trans point1 0 2) 2 3) ) trans2 (if (null world) (trans (trans point2 1 2) 2 3) (trans (trans point2 0 2) 2 3) ) ) (vla-put-MSpace doc :vlax-false) (vla-SetVariable doc "DIMLFAC" dimscale) (vla-SetVariable doc "osmode" 16384) (command "DIMLINEAR" trans1 trans2 (progn (vla-SetVariable doc "osmode" oldosnaps) (prompt "Specify dimension line location: ") pause ) ) (if (= ucsn "TempUCS") (command "_ucs" "_na" "_d" "TempUCS") ) (vla-put-MSpace doc :vlax-true) ) (prompt "\nCommand can only be used on one viewport at a time. \nInvalid point input. ") ) ) (vla-put-MSpace doc oldmspace) (vla-SetVariable doc "cmdecho" oldecho) (vla-SetVariable doc "osmode" oldosnaps) (vla-SetVariable doc "dimassoc" olddassoc) (vla-SetVariable doc "clayer" oldlay) (vla-put-ActiveDimStyle doc olddim) ) (progn (setq ename (ssname sset2 0) elist (entget ename) vpnumb (cdr (assoc 69 elist)) vpucso (cdr (assoc 110 elist)) vpucsx (cdr (assoc 111 elist)) vpucsy (cdr (assoc 112 elist)) named (cdr (assoc 345 elist)) vpucs (if (null named) "" (cdr (assoc 2 (entget named)))) world (and (equal vpucso '(0 0 0)) (equal vpucsx '(1 0 0)) (equal vpucsy '(0 1 0))) vpobj (vlax-ename->vla-object ename) vpscale (vla-get-CustomScale vpobj) dimscale (/ 1 vpscale) ) (if (= (vla-get-DisplayLocked vpobj) :vlax-false) (vla-put-DisplayLocked vpobj :vlax-true)) (vla-SetVariable doc "cmdecho" 0) (if (null world) (if (= vpucs "") (command "_ucs" "_v") (command "_ucs" "_na" "_r" vpucs) ) (command "_ucs" "_w") ) (while (setq point1 (getpoint "\nSpecify first extension line origin or <Exit>: ")) (if (= vpnumb (vlax-variant-value (vla-GetVariable doc "cvport"))) (progn (setq point2 (getpoint point1 "\nSpecify second extension line origin or <Exit>: ") trans1 (if (null world) (trans (trans point1 1 2) 2 3) (trans (trans point1 0 2) 2 3) ) trans2 (if (null world) (trans (trans point2 1 2) 2 3) (trans (trans point2 0 2) 2 3) ) ) (vla-put-MSpace doc :vlax-false) (vla-SetVariable doc "DIMLFAC" dimscale) (vla-SetVariable doc "osmode" 16384) (command "DIMLINEAR" trans1 trans2 (progn (vla-SetVariable doc "osmode" oldosnaps) (prompt "Specify dimension line location: ") pause ) ) (vla-put-MSpace doc :vlax-true) ) (prompt "\nCommand can only be used on one viewport at a time. \nInvalid point input. ") ) ) (vla-put-MSpace doc oldmspace) (vla-SetVariable doc "cmdecho" oldecho) (vla-SetVariable doc "osmode" oldosnaps) (vla-SetVariable doc "dimassoc" olddassoc) (vla-SetVariable doc "clayer" oldlay) (vla-put-ActiveDimStyle doc olddim) ) ) (if (= count 2) (if (= oldmspace :vlax-false) (progn (setq ename (ssname sset3 0) elist (entget ename) vpnumb (cdr (assoc 69 elist)) vpucso (cdr (assoc 110 elist)) vpucsx (cdr (assoc 111 elist)) vpucsy (cdr (assoc 112 elist)) named (cdr (assoc 345 elist)) vpucs (if (null named) "" (cdr (assoc 2 (entget named)))) world (and (equal vpucso '(0 0 0)) (equal vpucsx '(1 0 0)) (equal vpucsy '(0 1 0))) vpobj (vlax-ename->vla-object ename) vpscale (vla-get-CustomScale vpobj) dimscale (/ 1 vpscale) ) (if (= (vla-get-DisplayLocked vpobj) :vlax-false) (vla-put-DisplayLocked vpobj :vlax-true)) (vla-put-MSpace doc :vlax-true) (vla-SetVariable doc "cvport" vpnumb) (vla-SetVariable doc "cmdecho" 0) (if (null world) (if (= vpucs "") (command "_ucs" "_v") (command "_ucs" "_na" "_r" vpucs) ) (command "_ucs" "_w") ) (while (setq point1 (getpoint "\nSpecify first extension line origin or <Exit>: ")) (progn (setq point2 (getpoint point1 "\nSpecify second extension line origin or <Exit>: ") trans1 (if (null world) (trans (trans point1 1 2) 2 3) (trans (trans point1 0 2) 2 3) ) trans2 (if (null world) (trans (trans point2 1 2) 2 3) (trans (trans point2 0 2) 2 3) ) ) (vla-put-MSpace doc :vlax-false) (vla-SetVariable doc "DIMLFAC" dimscale) (vla-SetVariable doc "osmode" 16384) (command "DIMLINEAR" trans1 trans2 (progn (vla-SetVariable doc "osmode" oldosnaps) (prompt "Specify dimension line location: ") pause ) ) (vla-put-MSpace doc :vlax-true) ) ) (vla-put-MSpace doc oldmspace) (vla-SetVariable doc "cmdecho" oldecho) (vla-SetVariable doc "osmode" oldosnaps) (vla-SetVariable doc "dimassoc" olddassoc) (vla-SetVariable doc "clayer" oldlay) (vla-put-ActiveDimStyle doc olddim) ) (progn (setq ename (ssname sset2 0) elist (entget ename) vpnumb (cdr (assoc 69 elist)) vpucso (cdr (assoc 110 elist)) vpucsx (cdr (assoc 111 elist)) vpucsy (cdr (assoc 112 elist)) named (cdr (assoc 345 elist)) vpucs (if (null named) "" (cdr (assoc 2 (entget named)))) world (and (equal vpucso '(0 0 0)) (equal vpucsx '(1 0 0)) (equal vpucsy '(0 1 0))) vpobj (vlax-ename->vla-object ename) vpscale (vla-get-CustomScale vpobj) dimscale (/ 1 vpscale) ) (if (= (vla-get-DisplayLocked vpobj) :vlax-false) (vla-put-DisplayLocked vpobj :vlax-true)) (vla-SetVariable doc "cmdecho" 0) (if (null world) (if (= vpucs "") (command "_ucs" "_v") (command "_ucs" "_na" "_r" vpucs) ) (command "_ucs" "_w") ) (while (setq point1 (getpoint "\nSpecify first extension line origin or <Exit>: ")) (progn (setq point2 (getpoint point1 "\nSpecify second extension line origin or <Exit>: ") trans1 (if (null world) (trans (trans point1 1 2) 2 3) (trans (trans point1 0 2) 2 3) ) trans2 (if (null world) (trans (trans point2 1 2) 2 3) (trans (trans point2 0 2) 2 3) ) ) (vla-put-MSpace doc :vlax-false) (vla-SetVariable doc "DIMLFAC" dimscale) (vla-SetVariable doc "osmode" 16384) (command "DIMLINEAR" trans1 trans2 (progn (vla-SetVariable doc "osmode" oldosnaps) (prompt "Specify dimension line location: ") pause ) ) (vla-put-MSpace doc :vlax-true) ) ) (vla-put-MSpace doc oldmspace) (vla-SetVariable doc "cmdecho" oldecho) (vla-SetVariable doc "osmode" oldosnaps) (vla-SetVariable doc "dimassoc" olddassoc) (vla-SetVariable doc "clayer" oldlay) (vla-put-ActiveDimStyle doc olddim) ) ) (prompt "\nThere are no viewports created in this layout tab. ") ) ) ) (progn (setq oldecho (vlax-variant-value (vla-GetVariable doc "cmdecho")) oldosnaps (vlax-variant-value (vla-GetVariable doc "osmode")) olddassoc (vlax-variant-value (vla-GetVariable doc "dimassoc")) ) (vla-SetVariable doc "dimassoc" 1) (vla-SetVariable doc "cmdecho" 0) (while (setq point1 (getpoint "\nSpecify first extension line origin or <Exit>: ")) (progn (setq point2 (getpoint point1 "\nSpecify second extension line origin or <Exit>: ")) (vla-SetVariable doc "osmode" 16384) (command "DIMLINEAR" point1 point2 (progn (vla-SetVariable doc "osmode" oldosnaps) (prompt "Specify dimension line location: ") pause ) ) ) ) (vla-SetVariable doc "cmdecho" oldecho) (vla-SetVariable doc "osmode" oldosnaps) (vla-SetVariable doc "dimassoc" olddassoc) (vla-SetVariable doc "clayer" oldlay) (vla-put-ActiveDimStyle doc olddim) ) ) (princ) ) Quote
ksperopoulos Posted March 29, 2016 Author Posted March 29, 2016 Ok, I have attempted to attack this in a different way. Instead of activating modelspace, I am selecting the border of the viewport instead. This will prevent my need to apply the rotated UCS that is in paperspace to the UCS in modelspace. And I did what Clint suggested and used (getvar "worlducs") to determine the rotation of the UCS within paperspace. Now, if I am in WCS, everything works like it should. But when my UCS is rotated, I can't get by the first getpoint function. What am I doing wrong? (FYI - this is the abbreviated version again, but this time I included the whole if function for the part I am working on.) (setq world (getvar "worlducs")) (if (= world 1) (progn (setq ename (car (entsel "\nSelect a viewport for dimensioning: ")) elist (entget ename) cntr (cdr (assoc 10 elist)) width (cdr (assoc 40 elist)) height (cdr (assoc 41 elist)) halfwd (/ width 2) halfht (/ height 2) lowlt (list (- (car cntr) halfwd) (- (cadr cntr) halfht) (caddr cntr)) uprt (list (+ (car cntr) halfwd) (+ (cadr cntr) halfht) (caddr cntr)) vpobj (vlax-ename->vla-object ename) vpscale (vla-get-CustomScale vpobj) dimscale (/ 1 vpscale) ) (setvar "cmdecho" 0) (while (and (setq point1 (getpoint "\nSpecify first extension line origin or <Exit>: ")) (> (car point1) (car lowlt)) (< (car point1) (car uprt)) (> (cadr point1) (cadr lowlt)) (< (cadr point1) (cadr uprt)) (= (caddr point1) (caddr lowlt)) (= (caddr point1) (caddr uprt)) (setq point2 (getpoint point1 "\nSpecify second extension line origin or <Exit>: ")) (> (car point2) (car lowlt)) (< (car point2) (car uprt)) (> (cadr point2) (cadr lowlt)) (< (cadr point2) (cadr uprt)) (= (caddr point2) (caddr lowlt)) (= (caddr point2) (caddr uprt)) ) (progn (setvar "dimlfac" dimscale) (setvar "osmode" 16384) (command "DIMLINEAR" point1 point2 (progn (setvar "osmode" oldosnaps) (prompt "\nSpecify dimension line location: ") pause ) ) ) ) (setvar "cmdecho" oldecho) (setvar "osmode" oldosnaps) (setvar "dimassoc" olddassoc) (setvar "clayer" oldlay) (vla-put-ActiveDimStyle doc olddim) ) (progn (setq ename (car (entsel "\nSelect a viewport for dimensioning: ")) elist (entget ename) cntr (cdr (assoc 10 elist)) width (cdr (assoc 40 elist)) height (cdr (assoc 41 elist)) halfwd (/ width 2) halfht (/ height 2) lowlt (list (- (car cntr) halfwd) (- (cadr cntr) halfht) (caddr cntr)) uprt (list (+ (car cntr) halfwd) (+ (cadr cntr) halfht) (caddr cntr)) vpobj (vlax-ename->vla-object ename) vpscale (vla-get-CustomScale vpobj) dimscale (/ 1 vpscale) ) (setvar "cmdecho" 0) (while (and (setq point1 [color="red"](trans[/color] (getpoint "\nSpecify first extension line origin or <Exit>: ") [color="red"]1 0)[/color]) (> (car point1) (car lowlt)) (< (car point1) (car uprt)) (> (cadr point1) (cadr lowlt)) (< (cadr point1) (cadr uprt)) (= (caddr point1) (caddr lowlt)) (= (caddr point1) (caddr uprt)) (setq point2 [color="red"](trans[/color] (getpoint [color="red"](trans point1 0 1)[/color] "\nSpecify second extension line origin or <Exit>: ") [color="red"]1 0)[/color]) (> (car point2) (car lowlt)) (< (car point2) (car uprt)) (> (cadr point2) (cadr lowlt)) (< (cadr point2) (cadr uprt)) (= (caddr point2) (caddr lowlt)) (= (caddr point2) (caddr uprt)) ) (progn (setvar "dimlfac" dimscale) (setvar "osmode" 16384) (command "DIMLINEAR" point1 point2 (progn (setvar "osmode" oldosnaps) (prompt "\nSpecify dimension line location: ") pause ) ) ) ) (setvar "cmdecho" oldecho) (setvar "osmode" oldosnaps) (setvar "dimassoc" olddassoc) (setvar "clayer" oldlay) (vla-put-ActiveDimStyle doc olddim) ) ) Quote
cwake Posted March 29, 2016 Posted March 29, 2016 Hi Kyle, Perhaps the misunderstanding is in the form that the points need to be in when provided to a command like "DIMLINEAR". Off the top of my head I can't think of any command where the coordinates do not need to be expressed in the current coordinate system. Of course, that is in contrast to when you are creating or modifying entities using entmake, entmod, or the various activex methods. THEN you would need to apply transformations to obtain world coordinates (or sometimes OCS) if a UCS is active. So the transformations that you are applying to the selected points appear to only serve the purpose of checking whether or not they lie inside the selected viewport. If it was me, I'd write a sub-function to do that to avoid repeating code, and if you do an online search, I'm sure you could find some functions already written to do that, saving you the task. The potential good news in that is you don't really care what the current coordinate system is. You can still use (trans pt 1 0) to check if it lies inside the viewport even when the current coordinate system is world; it just means that the return value is the same as the input value. One final observation that I almost made the other day... I suspect what you are wanting to do with the OSMODE and 16384 is to turn it on or off but retain the previous values? If that is the case I think you want to be ADDING 16384 to the existing OSMODE value to turn it off, and then later SUBTRACTING 16384 from it to turn it back on again, rather than setting it to 16384? Hope that helps. Quote
ksperopoulos Posted March 29, 2016 Author Posted March 29, 2016 Thank you for the replies. See my comments below: Perhaps the misunderstanding is in the form that the points need to be in when provided to a command like "DIMLINEAR"... The points need to be in whatever the current UCS is. So if the UCS is set to "world", then the point should return the x/y/z value based upon a UCS origin of (0,0,0), an x-direction of (1,0,0), and a y-direction of (0,1,0). If the UCS has been rotated 23 degrees, then the point should return the x/y/z values based upon the modified UCS origin, x-direction, and y-direction. So the transformations that you are applying to the selected points appear to only serve the purpose of checking whether or not they lie inside the selected viewport. That is correct. Because our drawings may contain viewports with multiple scales, I want to limit the dimensioning to a particular viewport that the user has selected. One final observation that I almost made the other day... I suspect what you are wanting to do with the OSMODE and 16384 is to turn it on or off but retain the previous values? If that is the case I think you want to be ADDING 16384 to the existing OSMODE value to turn it off, and then later SUBTRACTING 16384 from it to turn it back on again, rather than setting it to 16384? Setting the OSMODE to 16384 temporarily suppresses the running osnaps, which is my intention. Quote
ksperopoulos Posted March 29, 2016 Author Posted March 29, 2016 I have no idea what I did to make it work, but after I shut down my session of AutoCAD, started it back up, and ran the command again, it worked like it was supposed to. Feel free to comment on any of my code, but from what I see now, it is working. Thank you guys for the insight. Quote
Grrr Posted March 29, 2016 Posted March 29, 2016 I have no idea what I did to make it work, but after I shut down my session of AutoCAD, started it back up, and ran the command again, it worked like it was supposed to. My guess is that you might have a definition, which needed to be re-defined, and the only way to do it is to relaunch AutoCAD. Atleast I had such experience with (defun layers) to get the layers list in my drawing, but after I make changes (delete/add layers) the list doesn't redefine, even with relaunching the lisp. Probably if it was a command definition (defun c:layers) it would update, or redefining the definition when the command definition is executed (theres an example from Lee Mac with defun-q). Quote
Recommended Posts
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.