TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Lupo76 on January 29, 2015, 07:30:42 AM

Title: Reassociate dimensions non-associative
Post by: Lupo76 on January 29, 2015, 07:30:42 AM
Hello everyone,
after a long search on the web I found this code:

Code: [Select]
(defun c:ReAss (/ ss i e d pt)
  (if (setq ss (ssget "_:L" '((0 . "DIMENSION"))))
    (repeat (setq i (sslength ss))
      (if
        (and (eq (cdr (assoc 100 (reverse (setq d (entget (setq e (ssname ss (setq i (1- i)))))))))
                 "AcDbAlignedDimension"
             )
             (nentselp (setq pt (trans (mapcar '(lambda (a b) (/ (+ a b) 2.))
                                               (cdr (assoc 13 d))
                                               (cdr (assoc 14 d))
                                       )
                                       0
                                       1
                                )
                       )
             )
        )
         (progn (command "_.dimreassociate" e "" "_S" "_non" pt)
                (while (eq 1 (logand 1 (getvar 'CMDACTIVE))) (command ""))
         )
      )
    )
  )
  (princ)
)


It works well.
However if I replace the first line with

  (if (setq ss (ssget '((0 . "DIMENSION"))))

or with

(if (setq ss (ssget "X" '((0 . "DIMENSION"))))

it does not work.
What is "_:L"?

Thanks in advance
Title: Re: Reassociate dimensions non-associative
Post by: Tharwat on January 29, 2015, 07:35:39 AM

What is "_:L"?

That is to filter objects on LOCKED layers .
Title: Re: Reassociate dimensions non-associative
Post by: Lupo76 on January 29, 2015, 08:19:01 AM
Ok, thanks for the reply. I did not know it.
However I do not understand why with the following code does not work?

Code: [Select]
(if (setq ss (ssget '((0 . "DIMENSION"))))

I noticed with no "_:L" the command (command "_.dimreassociate" .....) emits the error that the selected object is not a line, arc, etc..
I think this happens because the dimension should be associated with lwpolylines.
With (ssget "_:L") the command "_.dimreassociate" succeeds and also recognizes polylines, while without not work.

Any idea?
Title: Re: Reassociate dimensions non-associative
Post by: Lupo76 on January 31, 2015, 06:42:36 AM
With a little patience, I analyzed the code better and rewritten based on my habits:

Code: [Select]
(defun RiassociaQuote (selez / n ent1 d pt)
  (setvar "OSMODE" 0)
  (setq n 0)
  (setq ent1 (ssname selez n)) ;nome della prima entità della selezione
  (while (/= ent1 nil)
    (progn
      (if (= (vall 0 ent1) "DIMENSION")
        (progn
          (setq d (entget ent1))
          (setq pt (trans (mapcar '(lambda (a b) (/ (+ a b) 2.0)) (cdr (assoc 13 d))(cdr (assoc 14 d))) 0 1))
         
         
          (if (and
                (or
                  (eq (cdr (assoc 100 (reverse d))) "AcDbAlignedDimension")
                  (eq (cdr (assoc 100 (reverse d))) "AcDbRotatedDimension")
                )
                (nentselp pt)
              )
              (progn
                (command "_.dimreassociate" ent1 "" "_S" "_non" pt)
                (while (eq 1 (logand 1 (getvar 'CMDACTIVE))) (command ""))
              )
          )
        )
      )

      ;--
      (setq n (+ n 1))
      (setq ent1 (ssname selez n)) ;nome dell'oggetto successivo
    )
  )
)

But not always work correctly.
The problem is the following line:

Code: [Select]
(command "_.dimreassociate" ent1 "" "_S" "_non" pt)

In practice, even if the snap is turned off with "_non", the selection of the object through a point (pt), is very influenced by the value of the zoom.
So when in the vicinity of pt there are other nearby objects, is not always selected the correct object.

PS. I assure you that pt passes on a single object, but often are selected nearby objects.
Do you have any idea on how to get around this problem.
I have finished my resources and then ask for help to you.

Thanks in advance.
Title: Re: Reassociate dimensions non-associative
Post by: Marc'Antonio Alessi on January 31, 2015, 10:59:19 AM
Maybe PickBox = 0  ?
Title: Re: Reassociate dimensions non-associative
Post by: owenwengerd on January 31, 2015, 11:17:34 AM
In practice, even if the snap is turned off with "_non", the selection of the object through a point (pt), is very influenced by the value of the zoom.
So when in the vicinity of pt there are other nearby objects, is not always selected the correct object.

If you know which object you want, pass the entity name with the point in the same style as the return from (entsel):
(command "_.dimreassociate" ent1 "" "_S" (list entity pt))
Title: Re: Reassociate dimensions non-associative
Post by: alanjt on January 31, 2015, 11:49:55 AM
I recognize that code. It was a cadtutor post, if I remember correctly.
Glad you got it working.
Title: Re: Reassociate dimensions non-associative
Post by: Marc'Antonio Alessi on January 31, 2015, 12:16:12 PM
If you know which object you want, pass the entity name with the point in the same style as the return from (entsel):
(command "_.dimreassociate" ent1 "" "_S" (list entity pt))
:o
Title: Re: Reassociate dimensions non-associative
Post by: Lupo76 on February 01, 2015, 11:29:31 AM
Maybe PickBox = 0  ?

It could be the correct solution.
Unfortunately I now have a more serious problem to be solved and I can not try it right now.
I hope I can try by the end of next week.
Title: Re: Reassociate dimensions non-associative
Post by: Lupo76 on February 01, 2015, 11:30:34 AM
In practice, even if the snap is turned off with "_non", the selection of the object through a point (pt), is very influenced by the value of the zoom.
So when in the vicinity of pt there are other nearby objects, is not always selected the correct object.

If you know which object you want, pass the entity name with the point in the same style as the return from (entsel):
(command "_.dimreassociate" ent1 "" "_S" (list entity pt))

Unfortunately I do not know the entity to associate:-(
Title: Re: Reassociate dimensions non-associative
Post by: Lupo76 on February 05, 2015, 12:00:37 PM
Maybe PickBox = 0  ?

It Works! thank you!
Title: Re: Reassociate dimensions non-associative
Post by: Marc'Antonio Alessi on February 05, 2015, 03:37:45 PM
Maybe PickBox = 0  ?

It Works! thank you!
You welcome.  ;D
Title: Re: Reassociate dimensions non-associative
Post by: Lupo76 on February 06, 2015, 03:32:17 AM
Unfortunately, I have another problem connected.
The lisp contains the function (command).
Unfortunately I have to use it within a reactor.
In this case, so I can not use:
Code: [Select]
(command "_.dimreassociate" ent1 "" "_S" "_non" pt)
I tried with
Code: [Select]
(vl-cmdf "_.dimreassociate" ent1 "" "_S" "_non" pt)
but even this does not work inside a reactor  :cry: :cry:

Have you any suggestions?
Title: Re: Reassociate dimensions non-associative
Post by: Lupo76 on February 07, 2015, 01:16:49 PM
After several days and several attempts I managed to solve the problem by circumventing.
Now my application can work with no associative dimensions  :lmao:

Thank you all for the invaluable assistance  ;-)
Title: Re: Reassociate dimensions non-associative
Post by: roy_043 on February 08, 2015, 09:28:12 AM
...
The lisp contains the function (command).
Unfortunately I have to use it within a reactor.
...
Have you any suggestions?
In such cases you can try using a 'post process':
http://www.theswamp.org/index.php?topic=42826.msg505457#msg505457