load dimstyle manager from lisp?

load dimstyle manager from lisp?

Gh_man
Advocate Advocate
1,358 Views
9 Replies
Message 1 of 10

load dimstyle manager from lisp?

Gh_man
Advocate
Advocate

I'd like to load the dimstyle manager from a lisp, but (command "dimstyle") acts as if it was a -dimstyle when called from a lisp. This results in a command line interface, whereas I would like to have the mouse based dimstyle manager interface.

 

Ultimately, my goal is to be able to change dimstyles without changing the dimscale. My plan is to:

- read the current dimscale

- call the dimstyle manager

- have the user select a dimstyle

- change the new dimscale to match the old one

 

The only barrier is that the dimstyle selection is happening at the command line, which isn't user friendly.

0 Likes
Accepted solutions (1)
1,359 Views
9 Replies
Replies (9)
Message 2 of 10

CodeDing
Advisor
Advisor

@Gh_man,

 

I don't believe there's an effective way to allow for the user to select the DimStyle by open its menu and still be compatible with Lisp.

A few weeks ago I made a function that I believe can help you with letting the user select...

image.png

Hope this helps.

(defun c:NEWDS (/ ds dim styleList newStyle)
(if (not (> (setq ds (getvar 'DIMSCALE)) 0)) (setq ds 1.0))
(while (setq dim (tblnext "DimStyle" (null dim)))
    (setq styleList (cons (cdr (assoc 2 dim)) styleList))
);while
(setq newStyle (nth (DD:StringReturn styleList) styleList))
(command "-DIMSTYLE" "R" newStyle)
(setvar 'DIMSCALE ds)
(prompt (strcat "\nDimStyle " newStyle " applied with scale factor of " (rtos ds) "."))
(princ)
);defun

(defun DD:StringReturn (strList / tmp len promptStr initStr str#)
;Created by Denon Deterding, 13 Nov 2018
;IN: list of strings for user to select from
;OUT: user selected string as nth from strList (0 or 1 or 2 etc...); else nil
(cond
  	;return nil if no list provided, or list is empty
	((not (listp strList)) (prompt "\nList not provided to function.") (setq str# nil));cond 1
	((not (> (length strList) 0)) (prompt "\nEmpty list provided to function.") (setq str# nil));cond 2
	;otherwise begin work
	(t
		(setq len (length strList) initStr "1" promptStr "" tmp 0)
	 	;if more than one item in list, create initStr values
	 	(if (> len 1) (progn (repeat (- len 1) (setq initStr (strcat initStr " " (itoa (+ tmp 2))) tmp (1+ tmp))) (setq tmp 0)))
	 	;Create prompt string defaults for user
	 	(repeat len
			(setq promptStr (strcat promptStr (itoa (+ 1 tmp)) " ... " (nth tmp strList)) tmp (1+ tmp))
		  	(if (not (= tmp len)) (setq promptStr (strcat promptStr "/")))
	 	);repeat
	 	;use initStr for easy user selection
		(initget initStr 1)
	 	;convert user response to number correlating to nth in sizeList
		(setq str# (- (atoi (getkword (strcat "\nSelect a DimStyle [" promptStr "]: "))) 1))
	);cond 3
);cond
;return nth selection
str#
);defun

Best,

~DD

Message 3 of 10

ВeekeeCZ
Consultant
Consultant
Accepted solution

Here you go.

 

(progn (initcommandversion) (command "dimstyle"))
Message 4 of 10

CodeDing
Advisor
Advisor

@Gh_man,

 

Well @ВeekeeCZ just made that really simple. They should get credit for answering this post.

Implemented into code, here's my updated take:

(defun c:NEWDS (/ ds)
(if (not (> (setq ds (getvar 'DIMSCALE)) 0)) (setq ds 1.0))
(progn (initcommandversion) (command "dimstyle"))
(setvar 'DIMSCALE ds)
(prompt (strcat "\nNew DimStyle applied with scale factor of " (rtos ds) "."))
(princ)
);defun

Best,

~DD

 

 

Message 5 of 10

Gh_man
Advocate
Advocate

(accidental double post, deleted)

0 Likes
Message 6 of 10

Gh_man
Advocate
Advocate

@ВeekeeCZ wrote:

Here you go.

 

(progn (initcommandversion) (command "dimstyle"))


Great, that's exactly what I needed! It looks like you've got the answers to all my lisp questions this week, both in this post and the other one (which I've not finished working on).

 

Out of curiosity, what makes this line of code work? Testing individually, I see that (initcommandversion) results in a value of "T", which presumably is passed to (command "dimstyle") using progn. Is (command "dimstyle") looking for an argument before it runs?

0 Likes
Message 7 of 10

ВeekeeCZ
Consultant
Consultant

No no. The only relation between those is that (initcommandversion) is the predecessor. Even the (progn) I used due test purpose. It's the same relation as with (initdia) or (initget). See the HELP

 

Sometimes are AutoCAD and LISP versions of particular command different. Typically the EXPLODE. LISP version doesn't allow to explode selection sets (works just for a single entity or the first one of ss) unless you use (initcommandversion) (command "explode" ss "")

 

 

Message 8 of 10

Gh_man
Advocate
Advocate

@CodeDing wrote:

@Gh_man,

 

I don't believe there's an effective way to allow for the user to select the DimStyle by open its menu and still be compatible with Lisp.

A few weeks ago I made a function that I believe can help you with letting the user select...

image.png

Hope this helps.


 

This is also a good answer, the forum should allow accepting of multiple solutions! Most of my users like the mouse interface, but for the old school keyboarders, this is even faster than using a GUI.

Message 9 of 10

Gh_man
Advocate
Advocate

Sometimes are AutoCAD and LISP versions of particular command different. Typically the EXPLODE. LISP version doesn't allow to explode selections sets (works just for a single entity of the first one of ss) unless you use (initcommandversion) (command "explode" ss "")


 

Interesting! That's a useful bit of knowledge to add to my toolchest. I've run into that situation before, where a command worked differently in a LISP, and I didn't realize there was a way to force the desired behavior.

Many thanks for your help!

0 Likes
Message 10 of 10

scot-65
Advisor
Advisor
...and ARRAY

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes