Jump to content

# dimesnions Lisp to Get Dimension coordinates and Extension Line Angle

## Recommended Posts

How  can I retrieve both coordinates for a dimension including the angle of the extension line?

(I'm using Linear, Aligned and Arc Length dimensions).

I want to build a lisp that cycles through all the dimensions in the drawing and inserts a new block at the dimension coordinates using the extension line as the angle for the insert.

David

##### Share on other sites

I would use VL as you get a description of what dim variable, you can use also assoc code but there is lots for dims.

;   ExtLine1Point = (142.0 62.0 0.0)
;   ExtLine2Point = (324.841335614172 204.804222594522 0.0)

so get angle of the 2 points and add (/ pi 2.0)

```(setq oldang (getvar 'aunits))
(setvar 'aunits 3)
(setq obj (vlax-ename->vla-object (car (entsel "pick Dim"))))
(setq pt1 (vlax-get Obj 'ExtLine1Point))
(setq pt2 (vlax-get Obj 'ExtLine2Point))
(setq ang (+ (/ pi 2.0) (angle pt1 pt2)))
(command "-insert" "yourblock" pt1  1 1 ang))
(setvar 'aunits oldang)```

Edited by BIGAL
##### Share on other sites
On 11/12/2019 at 6:11 PM, BIGAL said:

I would use VL as you get a description of what dim variable, you can use also assoc code but there is lots for dims.

;   ExtLine1Point = (142.0 62.0 0.0)
;   ExtLine2Point = (324.841335614172 204.804222594522 0.0)

so get angle of the 2 points and add (/ pi 2.0)

```
(setq oldang (getvar 'aunits))
(setvar 'aunits 2)
(setq obj (vlax-ename->vla-object (car (entsel "pick Dim"))))
(setq pt1 (vlax-get Obj 'ExtLine1Point))
(setq pt2 (vlax-get Obj 'ExtLine2Point))
(setq ang (+ (/ pi 2.0) (angle pt1 pt2)))
(command pt1 "yourblock" 1 1 ang))
(setvar 'aunits oldang)```

Thanks for the help BigAl that works great..

I have tried to incorporate your code with some code from Lee Mac from his  dimensionsOverlap lisp to see if I could make cycle through all dimension and all type of dimensions.

But I ran into some issues... sometimes the insert is at mid point of the extension line and the angle is incorrect. I'm fairly new to lisp but here is my code below and the my test cad file is attached.

```(vl-load-com)
(defun c:gAddTick ( / cL cC pBlock bCount oldang pt1 pt2 )
(setq cL (getvar "CLAYER"))  ; Get Current layer
(setq cC (getvar "CECOLOR")) ; Get Current color
(setvar "CLAYER" "MyLayer")  ; Set the layer for insert
(setvar "CECOLOR" "ByLayer") ; Set Color by Layer
(setq oldang (getvar "aunits"))
(setvar 'aunits 2)
(setq pBlock "Myblock.dwg") ; Change "MyBlock.dwg" to desired block name

;; Get the Blocks collection
;; Cycle through all the blocks in collection
(vlax-for obj (vla-get-ModelSpace (vla-get-ActiveDocument (vlax-get-acad-object)))

(if (wcmatch  (vla-get-objectname obj) "AcDbAlignedDimension,AcDbRotatedDimension") ;  ;; Filter for Dimension objects only
(progn
(setq enx (entget (vlax-vla-object->ename obj))
ocs (cdr (assoc 210 enx))
pa (trans (cdr (assoc 10 enx)) 0 ocs)
p1 (trans (cdr (assoc 13 enx)) 0 ocs)
p2 (trans (cdr (assoc 14 enx)) 0 ocs)
)

(setq ang (+ (/ pi 2.0) (angle p2 pa)))
;Insert Block
(command "-insert" pBlock p1 1 1 ang)
(command "-insert" pBlock p2 1 1 ang)
)
(progn
(if (wcmatch  (vla-get-objectname obj) "AcDbArcDimension") ;  ;; Filter for Aarc Dimension objects only
(progn
(setq enx (entget (vlax-vla-object->ename obj))
ocs (cdr (assoc 210 enx))
pa (trans (cdr (assoc 15 enx)) 0 ocs)
p1 (trans (cdr (assoc 16 enx)) 0 ocs)
p2 (trans (cdr (assoc 17 enx)) 0 ocs)
)
(setq ang (+ (/ pi 2.0) (angle p1 pa)))
(command "-insert" pBlock p1 1 1 ang)

(setq ang (+ (/ pi 2.0) (angle p2 pa)))
(command "-insert" pBlock p2 1 1 ang)
)
(progn
;; Not a dimension  - skip this object in collection
)
)
)
)

)

(princ "\nDone...")
;Put Variables back to original State
(setvar "CLAYER" cL)
(setvar "CECOLOR" cC)
(setvar "aunits" oldang)
)```

Edited by DavidP
##### Share on other sites

A suggestion (vlax-for obj (vla-get-ModelSpace (vla-get-ActiveDocument (vlax-get-acad-object))) use ssget with the dim filter (0 . "DIMENSION") as the vl gets all objects.

The just use (repeat (setq x (sslength ss))

(setq obj (vlax-ename->vla-object (ssname ss (setq x (- x1)))))

then check for dim type.

I used the extline points not the insert points Need a bit of time the dims are complicated and variables are a bit over the place need to look at assoc dxf codes.

Edited by BIGAL

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

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