Author Topic: Why use _int or (setvar "osmode" 32) click same point, use UCS get error result  (Read 672 times)

0 Members and 1 Guest are viewing this topic.

masao

  • Newt
  • Posts: 97
hi

i have some question

i use getpoint can get coordinate. but use ucs coordinate is error.

if i use _int get intersection point coordinate is error.(use my drawing red line)

but use (setvar "osmode" 32) can get correct point.(but system get point is same)

white line is write in this drawing,use _int and (setvar "osmode" 32) can get same result.

why red line had different result?

Code: [Select]
(defun c:origin(/ e_lst osm yd)

(setq e_lst (mapcar (function (lambda (n) (list 'setvar n (getvar n)))) '("osmode" "cmdecho")))

(defun *error* (msg)

(mapcar 'eval e_lst)

(princ "")

)

 (vl-load-com)

 (setvar "cmdecho" 0)

 (setq osm (getvar "osmode"))

;(setvar "osmode" 32)

(setq yd (getpoint))

(setq yd (trans yd 1 0))

(vl-cmdf "_.ucs" "_origin" (trans yd 0 1))

(setvar "osmode" osm)

(princ)
)
(princ)
« Last Edit: January 13, 2024, 09:02:16 PM by masao »

JohnK

  • Administrator
  • Seagull
  • Posts: 10655
Re: have some question
« Reply #1 on: January 13, 2024, 03:17:21 PM »
Nice subject line. Very descriptive. You should have no problem getting knowledgable people (who are often very busy because they are knowledgeable) interested in clicking on your thread, try to understand your question, then try to understand your problem, then type up a response to you all because your thread subject line describes your question/problem so accurately and saves them time and effort.  -i.e. Having a good subject line, and question, saves busy people from having to do more work than necessary to help you thus helps you in the end.

I bet if you spent more than 2 minutes formulating your question and problem you will get more help. Busy people are tired of answering "I have a problem", or "layer question", or "code review", or...type questions.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2146
  • class keyThumper<T>:ILazy<T>
Re: have some question
« Reply #2 on: January 13, 2024, 04:18:42 PM »
@ masao

I'm not sure what the question was really, but here's what I assume is the answer.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:ucsSetOrigin (/ *error* e_lst)
  2.   (defun *error* (msg) (mapcar 'eval e_lst) (princ ""))
  3.   (setq e_lst
  4.          (mapcar (function
  5.                    (lambda (n) (list 'setvar n (getvar n)))
  6.                  )
  7.                  '("osmode" "cmdecho")
  8.          )
  9.   )
  10.  
  11.   (setvar "cmdecho" 0)
  12.   (setvar "osmode" 32)
  13.  
  14.   (vl-cmdf "_.ucs" "_origin" (getpoint))
  15.  
  16.   ;; restore system
  17.   (*error* nil)
  18.   (princ)
  19. )
  20.  

« Last Edit: January 13, 2024, 04:23:31 PM by kdub_nz »
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

masao

  • Newt
  • Posts: 97
Re: have some question
« Reply #3 on: January 13, 2024, 08:40:40 PM »
Nice subject line. Very descriptive. You should have no problem getting knowledgable people (who are often very busy because they are knowledgeable) interested in clicking on your thread, try to understand your question, then try to understand your problem, then type up a response to you all because your thread subject line describes your question/problem so accurately and saves them time and effort.  -i.e. Having a good subject line, and question, saves busy people from having to do more work than necessary to help you thus helps you in the end.

I bet if you spent more than 2 minutes formulating your question and problem you will get more help. Busy people are tired of answering "I have a problem", or "layer question", or "code review", or...type questions.

Sorry
I just know why click same point has different result.
I test many times but I don’t know this is cad bug or my code error.
Thank you so much.

masao

  • Newt
  • Posts: 97
Re: have some question
« Reply #4 on: January 13, 2024, 08:56:41 PM »
@ masao

I'm not sure what the question was really, but here's what I assume is the answer.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:ucsSetOrigin (/ *error* e_lst)
  2.   (defun *error* (msg) (mapcar 'eval e_lst) (princ ""))
  3.   (setq e_lst
  4.          (mapcar (function
  5.                    (lambda (n) (list 'setvar n (getvar n)))
  6.                  )
  7.                  '("osmode" "cmdecho")
  8.          )
  9.   )
  10.  
  11.   (setvar "cmdecho" 0)
  12.   (setvar "osmode" 32)
  13.  
  14.   (vl-cmdf "_.ucs" "_origin" (getpoint))
  15.  
  16.   ;; restore system
  17.   (*error* nil)
  18.   (princ)
  19. )
  20.  

Thank you so much,
I want know click same point has get different result is cad bug or my code error.
because I want to add else function on this code, so must use trans change coordinate.
If this is bug ,I add (setvar "osmode" 32) on code.
Can’t use _int to get point.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2146
  • class keyThumper<T>:ILazy<T>
@ masao

Does the code I posted give you the result you want ?

Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2146
  • class keyThumper<T>:ILazy<T>
I just tried my code again [ with  (setvar "osmode" 32) in the code ] and entered _mid at the command line when selecting the point.

The UCS origin was changed correctly to the point selected.

Regards,
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

masao

  • Newt
  • Posts: 97
I just tried my code again [ with  (setvar "osmode" 32) in the code ] and entered _mid at the command line when selecting the point.

The UCS origin was changed correctly to the point selected.

Regards,

Wait me a few times complete code.

masao

  • Newt
  • Posts: 97
I just tried my code again [ with  (setvar "osmode" 32) in the code ] and entered _mid at the command line when selecting the point.

The UCS origin was changed correctly to the point selected.

Regards,

i want fix coordinates origin and let origin change to my click point,but my drawing red lines has error.(maybe red lines has bug)

if i use (osmode 0) want to get intersection must use _int,but use _int get point is get error place on (command "UCS").

because i add else function on code , so use "trans" to get  coordinate.

if cant fix , i just add (osmode 32) on beginning of code.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:origin (/ e_lst osm yaundot yaundot_mono
  2.                  yaundot_datatype yaundot_line1
  3.                  yaundot_line1_datatype yaundot_line2
  4.                  yaundot_line2_datatype yaundot_line1_10 px
  5.                  py yaundot_line1_11 pxa pya
  6.                  yaundot_line2_10 px1 py1 yaundot_line2_11
  7.                  pxa1 pya1 pt1 pt2 pt3 pt4 call_word ss i
  8.                  ssn ssdata old_sswgyaundot new_ent
  9.                 )
  10.    (setq
  11.       e_lst (mapcar
  12.                (function
  13.                   (lambda (n) (list 'setvar n (getvar n)))
  14.                )
  15.                '("osmode" "cmdecho")
  16.             )
  17.    )
  18.    (defun *error* (msg) (mapcar 'eval e_lst) (princ ""))
  19.    (setvar "cmdecho" 0)
  20.    (setq osm (getvar "osmode"))
  21.    (initget "S T W")
  22.    (setq yaundot
  23.            (getpoint
  24.               "\n->origin point [object origin(S)/two lines intersection(T)/world(W)]:"
  25.            )
  26.    )
  27.    (cond
  28.       ((= yaundot "S")
  29.        (while (= yaundot_mono nil)
  30.           (setq yaundot_mono
  31.                   (car
  32.                      (entsel "\n->select coordinate:"
  33.                      )
  34.                   )
  35.           )
  36.           (while (= yaundot_mono nil)
  37.              (setq yaundot_mono
  38.                      (car (entsel
  39.                              "\n->select coordinate:"
  40.                           )
  41.                      )
  42.              )
  43.           )
  44.           (setq yaundot_datatype
  45.                   (cdr
  46.                      (assoc
  47.                         100
  48.                         (reverse
  49.                            (entget yaundot_mono)
  50.                         )
  51.                      )
  52.                   )
  53.           )
  54.           (if (/= yaundot_datatype "AcDbOrdinateDimension")
  55.              (progn (setq yaundot_mono nil
  56.                           yaundot_datatype nil
  57.                     )
  58.                     (princ "->not coordinate")
  59.              )                                              ;progn
  60.           )                                                 ;if
  61.        )                                                    ;while
  62.        (setq yaundot
  63.                (trans
  64.                   (cdr (assoc 10 (entget yaundot_mono)))
  65.                   0
  66.                   1
  67.                )
  68.        )
  69.       )                                                     ;yaundot "S"
  70.       ((= yaundot "T")
  71.        (while (= yaundot_line1 nil)
  72.           (setq yaundot_line1
  73.                   (car (entsel "\n->first line:"))
  74.           )
  75.           (while (= yaundot_line1 nil)
  76.              (setq yaundot_line1
  77.                      (car (entsel "\n->first line:")
  78.                      )
  79.              )
  80.           )
  81.           (setq yaundot_line1_datatype
  82.                   (cdr (assoc
  83.                           0
  84.                           (entget
  85.                              yaundot_line1
  86.                           )
  87.                        )
  88.                   )
  89.           )
  90.           (if (/= yaundot_line1_datatype "LINE")
  91.              (progn (setq yaundot_line1 nil
  92.                           yaundot_line1_datatype nil
  93.                     )
  94.                     (princ "->not line")
  95.              )                                              ;progn
  96.           )                                                 ;if
  97.        )                                                    ;while
  98.        (while (= yaundot_line2 nil)
  99.           (setq yaundot_line2
  100.                   (car (entsel "\n->second line:"))
  101.           )
  102.           (while (= yaundot_line2 nil)
  103.              (setq yaundot_line2
  104.                      (car
  105.                         (entsel "\n->second line:")
  106.                      )
  107.              )
  108.           )
  109.           (setq yaundot_line2_datatype
  110.                   (cdr (assoc
  111.                           0
  112.                           (entget
  113.                              yaundot_line2
  114.                           )
  115.                        )
  116.                   )
  117.           )
  118.           (if (/= yaundot_line2_datatype "LINE")
  119.              (progn (setq yaundot_line2 nil
  120.                           yaundot_line2_datatype nil
  121.                     )
  122.                     (princ "->not line")
  123.              )                                              ;progn
  124.           )                                                 ;if
  125.        )                                                    ;while
  126.        (setq yaundot_line1_10
  127.                (cdr (assoc 10
  128.                            (entget yaundot_line1)
  129.                     )
  130.                )
  131.        )
  132.        (setq px (car yaundot_line1_10))
  133.        (setq py (cadr yaundot_line1_10))
  134.        (setq yaundot_line1_11
  135.                (cdr (assoc 11
  136.                            (entget yaundot_line1)
  137.                     )
  138.                )
  139.        )
  140.        (setq pxa (car yaundot_line1_11))
  141.        (setq pya (cadr yaundot_line1_11))
  142.        (setq yaundot_line2_10
  143.                (cdr (assoc 10
  144.                            (entget yaundot_line2)
  145.                     )
  146.                )
  147.        )
  148.        (setq px1 (car yaundot_line2_10))
  149.        (setq py1 (cadr yaundot_line2_10))
  150.        (setq yaundot_line2_11
  151.                (cdr (assoc 11
  152.                            (entget yaundot_line2)
  153.                     )
  154.                )
  155.        )
  156.        (setq pxa1 (car yaundot_line2_11))
  157.        (setq pya1 (cadr yaundot_line2_11))
  158.        (setq pt1 (list px py))
  159.        (setq pt2 (list pxa pya))
  160.        (setq pt3 (list px1 py1))
  161.        (setq pt4 (list pxa1 pya1))
  162.        (setq
  163.           yaundot (trans (inters pt1 pt2 pt3 pt4 [onseg])
  164.                          0
  165.                          1
  166.                   )
  167.        )
  168.       )                                                     ;yaundot "T"
  169.       ((= yaundot "W")
  170.        (vl-cmdf "_.ucs" "_world")
  171.        (setq yaundot '(0 0 0))
  172.       )                                                     ;yaundot "W"
  173.    )                                                        ;cond
  174.    (setq yaundot (trans yaundot 1 0))
  175.    (vl-cmdf "_.ucs" "_origin" (trans yaundot 0 1))
  176.    (setq call_word (list-to-string yaundot))
  177.    (princ (strcat "\n->origin point:"
  178.                   "("
  179.                   (car call_word)
  180.                   " "
  181.                   (cadr call_word)
  182.                   " "
  183.                   (caddr call_word)
  184.                   ")"
  185.           )
  186.    )
  187.    (princ "\->select fix coordinates:")
  188.    (setq ss (ssget '((0 . "DIMENSION")
  189.                      (-4 . "<OR")
  190.                      (70 . 6)
  191.                      (70 . 38)
  192.                      (70 . 70)
  193.                      (70 . 102)
  194.                      (70 . 134)
  195.                      (70 . 166)
  196.                      (70 . 198)
  197.                      (70 . 230)
  198.                      (-4 . "OR>")
  199.                     )
  200.             )
  201.    )
  202.    (vl-cmdf "_.undo" "_begin")
  203.    (setvar "osmode" 0)
  204.    (setq i 0)
  205.    (repeat (sslength ss)
  206.       (setq ssn (ssname ss i))
  207.       (setq ssdata (entget ssn))
  208.       (setq old_sswgyaundot (cdr (assoc 10 ssdata)))
  209.       (setq new_ent (entget ssn))
  210.       (setq new_ent (subst (cons 10 yaundot)
  211.                            (assoc 10 (entget ssn))
  212.                            new_ent
  213.                     )
  214.       )
  215.       (entmod new_ent)
  216.       (setq i (1+ i))
  217.    )                                                        ;repeat
  218.    (setvar "osmode" osm)
  219.    (vl-cmdf "_.undo" "_end")
  220.    (princ)
  221. )
  222.  
  223.  
  224. (defun list-to-string (lst / x l)
  225.    (foreach x lst
  226.       (setq l (cons
  227.                  (vl-string-left-trim
  228.                     "("
  229.                     (vl-string-right-trim ")"
  230.                                           (vl-princ-to-string x)
  231.                     )
  232.                  )
  233.                  l
  234.               )
  235.       )
  236.    )
  237.    (reverse l)
  238. )

thank you so much.

if you use my drawing to test,first (setvar "osmode" 0) then to click point use _cen or _int , get point is correct but use "UCS" can't on this point.

but (setvar "osmode" 32) is OK.

(setvar "osmode" 32) and _int has different?

edit by Kerry add code=cadlisp-7 and format code structure
« Last Edit: January 13, 2024, 11:30:33 PM by kdub_nz »

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2146
  • class keyThumper<T>:ILazy<T>
It looks to me like you learnt nothing from the code I posted.

and I'll ask again,
Does the code I posted give you the result you want ?
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

ribarm

  • Gator
  • Posts: 3297
  • Marko Ribar, architect
It shouldn't be different - osmode 32 = intersection..., but if it's buggy, try to hardcode intersection with (osnap) function and prior set apperture to little bigger number than 6, i.e. 15 would be good...

Code: [Select]
(setq osm (getvar 'osmode))
(setvar 'osmode 32)
(setvar 'apperture 15)
(setq pt (osnap (getpoint) "_int"))
(setvar 'osmode osm)
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

masao

  • Newt
  • Posts: 97
It shouldn't be different - osmode 32 = intersection..., but if it's buggy, try to hardcode intersection with (osnap) function and prior set apperture to little bigger number than 6, i.e. 15 would be good...

Code: [Select]
(setq osm (getvar 'osmode))
(setvar 'osmode 32)
(setvar 'apperture 15)
(setq pt (osnap (getpoint) "_int"))
(setvar 'osmode osm)

OK,maybe is lines bug ,my drawing red lies has SPLINE , use _int get point is correct but use "UCS" can catch SPLINE curve fitting point.

but osmode 32 can't catch SPLINE curve fitting point.

so add (setvar 'osmode 32) on beginning of code is the easiest.

thanks all.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2146
  • class keyThumper<T>:ILazy<T>

This is like pulling teeth !
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2146
  • class keyThumper<T>:ILazy<T>
@ masao

Has your issue been resolved ?
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.