Jump to content

Recommended Posts

Posted

I am trying to write a lisp routine that dimensions horizontal and vertical deviations from design:

 

(defun c:ddxy ()

(setq p1 (getpoint "Surveyed point :"))

(setq p2 (getpoint "Design point :"))

(command "dimlinear" p1 p2 "_v" pause)

(command "dimlinear" p1 p2 "_h" pause)

)

 

p1 is typically a point object

p2 is typically the end point of a line or centre of a circle

 

When I run this lisp, the first dim created is associated correctly with both objects, but the second dim is non-associative.

 

I can of course manually create each individual horizontal & vertical dimension but I was hoping to cut my workload in half and let lisp do the repetitive bit of the operation for me!

 

Can anyone help fix this? I have tried playing with osnap settings and sending the first dim to the back before creating the second dim but to no avail.

 

Thanks,

 

Rob

  • 2 years later...
Posted

Does anyone know how create an associative dimension without using the command function?

 

 

(defun c:test ( / p1 p2 ang )
   (if
       (and (setq p1 (getpoint "\nSpecify first point of dimension: "))
           (setq p2 (getpoint p1 "\nSpecify second point of dimension: "))
       )
       (vla-adddimrotated 
           (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object)))
           (vlax-3d-point p1) (vlax-3d-point p2)
           (vlax-3d-point (polar p1 (+ (* 0.5 pi) (setq ang (angle p1 p2))) (distance p1 p2)))
           ang
       )
   ) (princ)
)

Posted

Set the sysvar DIMASSOC to 2, and all new dims will default to Associative. Not sure this will be relevant but do not have the NODE osnap on, unless you want the dims to be associative to each other rather than the objects. The last object drawn, usually the dimensions, are on top so that is the first snap you will encounter.

Posted

That doesn't work when creating dimensions in lisp (Unless you're using the command function).

Posted (edited)

Am I going in the right direction?

 

(vla-AddObject dict "ACDBVARIABLEDICTIONARY" "AcDbDictionary")

 

 

 

Edit:

 

I'd like to expand. When researching before I found this (see below). My guess is I would have to make Dimassoc and add it to the dimensions extension dictionary.

 

AcDbVariableDictionary CANNOSCALE CMLEADERSTYLE CTABLESTYLE CVIEWDETAILSTYLE CVIEWSECTIONSTYLE DIMASSOC HIDETEXT LAYEREVAL LAYERNOTIFY

Edited by Lt Dan's legs
Posted (edited)

Soooo, here's my approach that did NOT work.

 

(setq dic (handent (vla-get-handle (vla-getextensiondictionary dim))))
; blck = block that the dimension is pointing to
; inobj = inside object the snap point is pointing to
; inobj2 = inside object the snap point is pointing to
(setq da
(entmakex
 (list
   (cons 0 "DIMASSOC") 
   (cons 330 dic)
   (cons 100 "AcDbDimAssoc")
   (cons 330 dim)
   (cons 90 3)
   (cons 70 0)
   (cons 71 0)
   (cons 1 "AcDbOsnapPointRef")
   (cons 72 1)
   (cons 331 blck)
   (cons 331 inobj)
   (cons 73 2)
   (cons 91 3)
   (cons 40 1.0)
   (cons 10 '(0.0 0.0 2.0e+050))
   (cons 75 0)
   (cons 1 "AcDbOsnapPointRef")
   (cons 331 blck)
   (cons 331 inobj2)
   (cons 72 1)
   (cons 73 2)
   (cons 91 3)
   (cons 40 1.0)
   (cons 10 '(0.0 0.0 2.0e+050))
   (cons 75 0)
 )
))
(entmod (append (entget dic)(list (cons 3 "ACAD_DIMASSOC") (cons 360 da))))

Edited by Lt Dan's legs
Posted

It says associative but never reacts when the line is modified...

Untitled.jpg

Posted

Lee, do you know what other Dictionaries this could possibly be under? I can post an updated lsp if that helps...

Posted

Sorry for my English.

I have a similar problem.

A partial solution was found on the russian CAD-forum in 2007.

Dimention reacts when the lines is modified, but it's not real assoсiative.

 

(defun EditDimassoc (ent_list dict_id / length_list i el el1 ent_list_new)
  (setq ent_list_new '())
  (setq length_list (length ent_list))
  (setq i 0 )
  (while (< i length_list)
     (setq el (nth i ent_list))
     (if (= i 2)
        (progn
           (setq el1 (list '(102 . "{ACAD_REACTORS") (cons 330 dict_id) '(102 . "}") (cons 330 dict_id)))
           (setq ent_list_new (append ent_list_new el1))
        ); end progn
        (setq ent_list_new (append ent_list_new (list el)))
     ); end if
     (setq i (1+ i))
  ); end while
  ent_list_new
); end defun
;--------------------------------------------------------------------------------------------
(defun EditDimension (ent_list dict_id dimassoc_id / length_list i el el1 ent_list_new)
  (setq ent_list_new '())
  (setq length_list (length ent_list))
  (setq i 0 )
  (while (< i length_list)
     (setq el (nth i ent_list))
     (if (= i 2)
        (progn
           (setq el1 (list '(102 . "{ACAD_XDICTIONARY") (cons 330 dict_id) '(102 . "}")
                                   '(102 . "{ACAD_REACTORS") (cons 330 dimassoc_id) '(102 . "}")
                                    el))
           (setq ent_list_new (append ent_list_new el1))
        ); end progn
        (setq ent_list_new (append ent_list_new (list el)))
     ); end if
     (setq i (1+ i))
  ); end while
  ent_list_new
); end defun
;--------------------------------------------------------------------------------------------
(defun SetDimAssoc (obj1 obj2 / dim_id dim_list dimassoc_id dimassoc_list dict_id dict_list )
  (setq dim_id dim_obj)
  (setq dim_list (entget dim_id))
  (setq dimassoc_id (entmakex (list '(0 . "DIMASSOC")
                                                  '(100 . "AcDbDimAssoc")  (cons 330 dim_id)
                                                  '(90 . 3) '(70 . 0) '(71 . 0)
                                                  '(1 . "AcDbOsnapPointRef") (cons 331 obj1)
                                                  '(72 . 13) '(40 . 1.0) (cons 10 (cdr (assoc 10 (entget obj1))))
                                                  '(1 . "AcDbOsnapPointRef") (cons 331 obj2)
                                                  '(72 . 1) '(40 . 1.0)   (cons 11 (cdr (assoc 10 (entget obj2))))
                                         );list
                             );entmake
  );setq
  (setq dimassoc_list (entget dimassoc_id))
  (entmod dimassoc_list)
  (setq dict_id (entmakex (list '(0 . "DICTIONARY")
                                               (cons 330 dim_id)
                                               '(100 . "AcDbDictionary")
                                               '(280 . 1) '(281 . 1)
                                               '(3 . "ACAD_DIMASSOC")
                                               (cons 360 dimassoc_id)
                                      );list
                       );entmake
  )
  (setq dict_list (entget dict_id))
  (entmod dict_list)
  (setq dict_list (EditDimassoc dimassoc_list dict_id))
  (entmod dict_list)
  (setq dim_list (EditDimension dim_list dict_id dimassoc_id))
  (entmod dim_list)
  (entupd dim_id)
); end defun
(defun Test_DimAssoc ( / line1 line2 line3 ang doc mspace obj dim_obj)
  (command "_line" '(0 0) '(0 100) "")
  (setq line1 (entlast))
  (command "_line" '(0 100) '(100 100) "")
  (setq line2 (entlast))
  (command "_line" '(100 100) '(150 0) "")
  (setq line3 (entlast))
  (setq ang 0)
  (setq doc (vla-get-activeDocument (vlax-get-acad-object)))
  (setq mspace (vla-get-modelSpace doc))
  (setq obj (vla-addDimRotated mspace (vlax-3d-point (cdr (assoc 10 (entget line2))))
                                                        (vlax-3d-point (cdr (assoc 11 (entget line3))))
                                                        (vlax-3d-point '(100 150))
                                                        ang))
  (setq dim_obj (vlax-vla-object->ename obj))
  (vlax-release-object obj)
  (SetDimAssoc line2 line3)
  (princ)
); end defun
(Test_DimAssoc)

Posted

Thank you for your input! It made me go back and look at my approach. I noticed I was forgetting something

 

 

 

 

code below works with an existing dimension that's not already associative

 

(defun c:Dassoc ( / _dimension _object _extensiondictionary _dimassoc _number _list )
 (if
   (and (setq _dimension (car (entsel "\nSpecify Dimension: ")))
     (or (wcmatch (cdadr (setq _dimension (entget _dimension))) "*DIMENSION*")
        (alert "You must select a dimension to continue!")
     )
     (setq _object (car (entsel "\nSpecify line associate with: ")))
     (or (wcmatch (cdadr (entget _object)) "LINE")
        (alert "You must select a Line to continue!")
     )
   )
   (progn
     (setq _extensiondictionary 
       (handent 
         (vla-get-handle 
           (vla-getextensiondictionary 
             (vlax-ename->vla-object (cdar _dimension))
           )
         )
       )
     )
     (setq _dimassoc
       (entmakex
         (list
           (cons 0 "DIMASSOC")
           (cons 100 "AcDbDimAssoc")
           (cons 330 (cdar _dimension))
           (cons 90 3)
           (cons 70 0)
           (cons 71 0)
           (cons 1 "AcDbOsnapPointRef")
           (cons 72 1)
           (cons 331 _object)
           (cons 73 13)
           (cons 91 3)
           (cons 40 1.0)
           (cons 10 '(0.0 0.0 2.0e+050))
           (cons 75 0)
           (cons 1 "AcDbOsnapPointRef")
           (cons 331 _object)
           (cons 72 1)
           (cons 73 2)
           (cons 91 3)
           (cons 40 1.0)
           (cons 10 '(0.0 0.0 2.0e+050))
           (cons 75 0)
         )
       )
     )
     (entmod 
       (append (entget _extensiondictionary)
         (list (cons 3 "ACAD_DIMASSOC") (cons 360 _dimassoc))
       )
     )
     (setq _number (vl-position (assoc 330 _dimension) _dimension))
     (repeat _number
       (setq _list (cons (nth (setq _number (1- _number)) _dimension) _list))
     )
     (entmod
       (append _list
         (list '(102 . "{ACAD_XDICTIONARY") (cons 330 _extensiondictionary) '(102 . "}") 
           '(102 . "{ACAD_REACTORS") (cons 330  _dimassoc) '(102 . "}")
         )
         (member (assoc 330 _dimension) _dimension)
       )
     )
   )
 ) (princ)
)

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...