PDA

View Full Version : Setting dimscale



kieren
2004-06-24, 08:34 AM
I am looking for a routine to set the dimscale variable by selecting an existing dimension.
Is this possible?

Many thanks

..::KIEREN::..

msretenovic
2004-06-24, 01:44 PM
Give this a try:



;;-INFO-
;; Description: MKSxMDimCur makes the dimstyle of the selected object current.
;; Alias: md
;; Created by: Michael K. Sretenovic`
;;Requested by: Michael K. Sretenovic`
;;Date created: 06-24-2004
;;Modification Notes:
;;
;;-INFO-
(defun c:MKSxMDimCur
(
/
dCol ;;variable - dimstyle collection
dList ;;variable - list of supported dimension objects
dObj ;;variable - dimension object
doc ;;variable - current active drawing
dType ;;variable - style name of dimension
obj ;;variable - object to check
*Error* ;;function - standard error handler
)
;;*Error* - standard error handler: (*Error* msg)
(defun *Error*(msg / flag)
(vla-endUndoMark doc)
(cond
((not msg))
((member (strcase msg t) '("console break" "function cancelled" "quit / exit abort"))(setq flag t))
((princ (strcat "\nError: " msg)) (setq flag t))
)
(if flag (vl-cmdf "._u"))
(princ)
)
;;Main - main portion of routine
(setq doc (vla-get-activeDocument (vlax-get-acad-object))
dCol (vla-get-dimStyles doc) ;get dimstyle collection
dList (list
"AcDbRotatedDimension"
"AcDbAlignedDimension"
"AcDbLeader"
"AcDb2LineAngularDimension"
"AcDbRadialDimension"
"AcDbDiametricDimension"
) ;create list of dim objects
)
(vla-startUndoMark doc) ;set undo mark
(princ "\n\nSelect dimension to make current: ")
(while (not obj)
(if (not (member (vla-get-objectName (setq obj (vlax-ename->vla-object (ssname (ssget ":S") 0)))) dList))
(setq obj nil) ;if not in list, set to nil
)
)
(setq dType (vla-get-styleName obj))
(vlax-for dObj dCol ;loop to find dimstyle in dimstyle collection
(if (= (vla-get-name dObj) dType)
(setq dType dObj)
)
)
(vla-put-activeDimStyle doc dType) ;set dimstyle current
(*Error* nil)
)

whdjr
2004-06-24, 01:46 PM
kieren,

Here is a little something I cooked up. Hope you like it.
This was tested in A2K, but should work in newer versions as well.



(defun c:dc (/ ss dim echo)
(princ "\nSelect a Dimension to make current: ")
(while (not ss)
(setq ss (ssget '((0 . "DIMENSION"))))
(if ss
(if (> (sslength ss) 1)
(and (princ
"\nToo many Dimensions selected. Please select only one. "
)
(setq ss nil)
)
)
(princ "\nNothing selected. Please try again. ")
)
)
(setq echo (getvar "cmdecho"))
(if (eq echo 1)
(setvar "cmdecho" 0)
)
(setq dim (cdr (assoc 3 (entget (ssname ss 0)))))
(command "-DIMSTYLE" "restore" dim)
(setvar "cmdecho" echo)
(princ (strcat "\nDimstyle has been changed to " dim))
(princ)
)

kieren
2004-06-24, 03:28 PM
Thanks guys, but not quite what I meant! (though those routines will prove v useful!)

I would like to get the dimscale value of an existing dimension and then update my global variable (dimscale) to that value.

ie. (see if this makes any sense!):
dimscale value in an existing drawing is 1.
An existing dimension in that drawing has been created with a dimscale value of 25.
I would like to extract that value of 25 and set my global "dimscale" variable to that value.

I have routines that insert blocks to the variable "dimscale", so by selecting an existing dimension, I can insert the blocks at that chosen scale, without having to manually check and adjust the dimscale variable.

Hope thats a bit clearer?!

Many thanks,
..::KIEREN::..

whdjr
2004-06-24, 04:12 PM
Kieren,

That's exactly what it does.
Can you elaborate any more clearly on what your trying to do.

kieren
2004-06-24, 04:27 PM
I'll try Will!

From what I can see (and tried!), you code sets the dimstyle to another selected existing dimension?

I am just trying to extract the "dimscale" variable, not all the "dimstyle" settings.

If an existing dim on the drawing has been drawn with variable "dimscale" set to 25, then I want to be able to automate the following command line sequence based on that variable:

----------------------------
Command: dimscale
Enter new value for DIMSCALE <1.0000>: 25
-----------------------------

Hope that's clearer?
That's all I'm trying to do!!!! :banghead:

..::KIEREN::..

stig.madsen
2004-06-24, 04:41 PM
This will override DIMSCALE with a value depending on:
1. If chosen dimension has overriden DIMSCALE then use this
2. Otherwise, use DIMSCALE of chosen dimensions dimension style

Is that what you're looking for?


(defun C:SetDS (/ ent entl dscale dstyle)
(cond
((and (setq ent (entsel "\nSelect dimension object: "))
(= (cdr (assoc 0 (setq entl (entget (car ent) '("ACAD")))))
"DIMENSION"
)
)
(cond ((setq dscale (cdr (assoc 1040 (cdadr (assoc -3 entl))))))
((setq dstyle (tblsearch "DIMSTYLE" (cdr (assoc 3 entl))))
(setq dscale (cdr (assoc 40 dstyle)))
)
)
)
)
(and dscale (setvar "DIMSCALE" dscale))
)

kieren
2004-06-24, 04:44 PM
Perfect!!

Thanks Stig, much appreciated.

..::KIEREN::..

stig.madsen
2004-06-24, 04:48 PM
You're welcome