Jump to content
3dwannab

Addition in commandline while in command

Recommended Posts

3dwannab

Hi all,

 

Is this possible. I was wanting to say stretch a wall in brick dimensions so would it be possible to type the equivalent of '225*9' (which doesn't work) while in the stretch command to give me the correct value every time. Would be a huge time saver at the moment.

 

Even via lisp or any program for brick dims would be sweet.

Share this post


Link to post
Share on other sites
steven-g

You can use 'cal transparently (in the middle of a command) just type the hyphen first

Share this post


Link to post
Share on other sites
3dwannab
You can use 'cal transparently (in the middle of a command) just type the hyphen first

I don't say this lightly! LEGEND

 

Commandline output if anyone has trouble figuring it out.

Specify base point or [Displacement] <Displacement>:
Specify second point or <use first point as displacement>: 'CAL
>>>> Expression: 225*10
Resuming STRETCH command.
Specify second point or <use first point as displacement>: 2250

Share this post


Link to post
Share on other sites
3dwannab

Sorry, is then possible to pick a distance and have that value enter the 'cal command? If you understand?

 

like:

 

215*distance

Share this post


Link to post
Share on other sites
steven-g

It probably is, but it can give unexpected results depending on how you use it and how you pick points, for example you could put this

'cal;dist(cur,cur)*215;

into a toolpalette macro and use it in the middle of a command but it will stretch the objects in the direction of the cursor position when you picked the second point ? So you need to be specific when creating a macro, can you post a drawing to show what you mean, with an example of what needs stretching and where all your pick points would be.

 

 

EDIT

This is probably really easy in LISP if anyone else cares to jump in

Share this post


Link to post
Share on other sites
tombu

QuickCal Palette "Ctrl + 8" has a lot of functions including buttons along the top for "Get Coordinates", "Distance Between Two Points", & "Angle of Line Defined by Two Points". Another button to "Paste value to command line".

Share this post


Link to post
Share on other sites
rkent

When prompted for the second point of displacement you can type

(* 225 9)

no need to start 'cal first.

 

If you use this for divide be sure to include a decimal point or it will round off.

(/ 13 3) will give the answer as 4, (/ 13 3.0) will return 4.3333

 

You can use this without a command active if you just want to do some quick math.

Share this post


Link to post
Share on other sites
Dana W

I use a single row array in a dynamic block with a stretch action/parameter for this very thing, only my bricks are 8" lengths of ICF, insulated concrete forms, in plan view.

 

Simply draw up one brick, make a single row array of it, select it, click the Create block button, apply a stretch parameter, and a stretch action to the array, save it, and done. Then all I have to do is insert the block where needed, and stretch it until the proper number of elements are showing. The array is self incrementing so no other parameters are needed in the block.

Share this post


Link to post
Share on other sites
3dwannab

At rkent, thank you for the tip to use the command line for the calculater. :notworthy:

 

Just what I was looking for.

 

If I have the patience (know-how) I might try write a lisp to say type 'brick' in the commandline and it'll go into the stretch command. Ask whether its a co-, co, or co+ brick course (-|co|+) then the course no. or even total length of the course of bricks.

 

@ Dana W: Good idea, but I have the F7 button mapped to the _snapfrom command so I normally snap from a corner and give the brick dim then.

 

 

A Todos

I'm learning maxscript atm so my brian is a little fried from that at the moment. If I'm successful I'll make sure and post it.

 

Share this post


Link to post
Share on other sites
3dwannab

So, I've decided to try (and I use that term lightly) write a .lsp for this.

 

I searched for a .lsp and was lucky enough to find the below code which is close to what I'm after.

 

Original Post by Kiwi Russ

http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/stretch-command-through-autolisp/m-p/1946435#M237968

(defun C:STRTCH (/ X Y PT1 PT2 SS SS1 SS2 A OS EN ECHO)
(setq ECHO (getvar "CMDECHO"))
(setvar "CMDECHO" 0)
(setq os (getvar "OSMODE"))
(setvar "OSMODE" 0)

(prompt "\n X Distance to Stretch: < 0 >")
(setq X (getstring))
(if (= X "")(setq X "0"))
(prompt "\n Y Distance to Stretch: < 0 > ")
(setq Y (getstring))
(if (= Y "")(setq Y "0"))
(setq A (strcat "@" X "," Y))

(setq PT1 (getpoint "\n Select Entities to Stretch by Crossing Window:"))
(prompt "\n 1st Point:")
(setq PT2 (getcorner PT1 "\n 2nd Point:"))


(prompt "\n Remove Entities..... Add Entities: ")
(command "Select" "c" PT1 PT2 pause)
(setq SS (ssget "p")) ;
(setq SS1 (ssget "c" PT1 PT2))
(setq SS2 (ssadd))
(while ( setq EN (ssname SS1 0))
(if (null (ssmemb EN SS))
	(ssadd EN SS2)
);if
(ssdel EN SS1)
);while
(if (< 0 (sslength SS2))
(command "select" SS2 "" "stretch" "C" PT1 PT2 "R" "P" "" "" A)
(command "stretch" "c" PT1 PT2 PT1 "" "" A)
);if
(setvar "OSMODE" OS)
(setvar "CMDECHO" ECHO)
(princ)
);end strtch.lsp

 

The only line I've added so far is:

(if (/= X "")(setq X (itoa (* X 225))))

 

I've tried to pass the variable X and multiply it by 225 but that returns an error.

; error: bad argument type: numberp: "2"

Can you not pass variables through lisps like this.

 

The same will be said for y.

 

So my full code so far is:

(defun C:B_STRETCH (/ X Y PT1 PT2 SS SS1 SS2 A OS EN ECHO)
(setq ECHO (getvar "CMDECHO"))
(setvar "CMDECHO" 0)
(setq os (getvar "OSMODE"))
(setvar "OSMODE" 0)

(prompt "\n X no. of bricks: < 0 >")
(setq X (getstring))

(if (= X "")(setq X "0"))

; Broken code
; (if (/= X "")(setq X (itoa (* X 225))))

(prompt "\n Y no. of bricks: < 0 > ")
(setq Y (getstring))
(if (= Y "")(setq Y "0"))

; Broken code
; (if (/= Y "")(setq Y (itoa (* Y 225))))

#|

Could it be possible to add a dropdown to the value 255 above in the X and Y to ask the user for:

215 = "CO -"
225 = "CO"
235 = "CO+"

If either of x or y == 0 then it will not ask this.

The script doesn't ask for a basepoint either. Is this hard to change?

|#

(setq A (strcat "@" X "," Y))

(setq PT1 (getpoint "\n Select Entities to Stretch by Crossing Window:"))
(prompt "\n 1st Point:")
(setq PT2 (getcorner PT1 "\n 2nd Point:"))

(prompt "\n Remove Entities..... Add Entities: ")
(command "Select" "c" PT1 PT2 pause)
(setq SS (ssget "p"))

(setq SS1 (ssget "c" PT1 PT2))
(setq SS2 (ssadd))

(while ( setq EN (ssname SS1 0))
	(if (null (ssmemb EN SS))
		(ssadd EN SS2)
		)
	(ssdel EN SS1)
	)
(if (< 0 (sslength SS2))
	(command "select" SS2 "" "stretch" "C" PT1 PT2 "R" "P" "" "" A)
	(command "stretch" "c" PT1 PT2 PT1 "" "" A)
	)
(setvar "OSMODE" OS)
(setvar "CMDECHO" ECHO)
(princ)
)

 

It would be nice to have a dropdown to ask if it's a 215,225,235 course after giving the number in x or y.

If either of x or y == 0 then it will not ask this.

 

The script doesn't ask for a basepoint either. Is this hard to change?

 

 

Any help would be greatly appreciated.

Share this post


Link to post
Share on other sites
tombu

You cannot multiply a string, try:

(if (/= X "")(setq X (itoa (* (atoi X) 225))))

Share this post


Link to post
Share on other sites
BIGAL

Like Rkent watch out for decimal point, I use cal all the time I have road cross sections scale 1;100 H 1:50 Ver so if I want a level I draw a circle and use C pt 'cal 20.*(datum-level) which shows crossing point for say a sewer.

 

If you look up the help for cal, did you know you can do stuff like draw a circle twice the radius of a picked circle, 'cal c pt rad*2. do not need to know the size of the original circle. There is all sorts of stuff like work out 1/4 distance of line, mid pt compare to m2p. We tend to write a lisp when its built into 'cal.

Share this post


Link to post
Share on other sites
BIGAL
It would be nice to have a dropdown

 

There is a way of having simple pop up input and that is using a side bar menu, unfortunately Autodesk have not dropped it but never talk about it. You can have all sorts of preset values.

 

side menu example pick number of bricks but menu returns actual size.

**brickwid 
[AutoCAD]^C^C^P$S=X $S=S
[select] 
[no of] 
[bricks]

[ 0.5]110
[ 1.0]230
[ 1.5]360
[ 2.0]470
[ 2.5]590
[ 3.0]710
[ 3.5]830
[ 4.0]950
[ 4.5]1070
[ 5.0]1190
[ 5.5]1310
[ 6.0]1430

Share this post


Link to post
Share on other sites
tombu
Could it be possible to add a dropdown to the value 255 above in the X and Y to ask the user for:

 

215 = "CO -"

225 = "CO"

235 = "CO+"

 

If either of x or y == 0 then it will not ask this.

 

The script doesn't ask for a basepoint either. Is this hard to change?

 

 

It would be nice to have a dropdown to ask if it's a 215,225,235 course after giving the number in x or y.

If either of x or y == 0 then it will not ask this.

It's actually not hard to do.

 

Take a look at Lee Mac's tutorial - Prompting with a Default Option http://www.lee-mac.com/promptwithdefault.html

It gives the user the options with the mouse to select options either from the command line or from a right-click menu while allowing keyboard selection options as well.

 

Never understood why AutoCAD's lisp help for getkword doesn't include how to do anything like this.

Share this post


Link to post
Share on other sites
3dwannab

Thanks tombu. I was already on that page. I did find getkword hidden at the bottom of the page in the initget part of the help. ;)

http://help.autodesk.com/view/ACD/2016/ENU/?guid=GUID-9ED8841B-5C1D-4B3F-9F3B-84A4408A6BBF

 

The initget function provides support for localized keywords. The following syntax for the keyword string allows input of the localized keyword while it returns the language independent keyword:

"local1 local2 localn _indep1 indep2 indepn"

where local1 through localn are the localized keywords, and indep1 through indepn are the language-independent keywords.

There must always be the same number of localized keywords as language-independent keywords, and the first language-independent keyword is prefixed by an underscore as shown in the following example:

(initget "Abc Def _Ghi Jkl")

(getkword "\nEnter an option (Abc/Def): ")

Entering A returns Ghi and entering _J returns Jkl.

Not really sure what the _Ghi Jkl part do!

 

 

I've got this script to work (kind of). You have to actually click on one of the three options to work [215mm/225mm/235mm/Custom]. Pressing enter doesn't use the defualt. I fixed this by using:

(if (not ansx) (setq x (itoa (* (atoi x) 215))))

&

(if (not ansy) (setq y (itoa (* (atoi y) 215))))

 

Is this the correct method for doing so? It seems hacky.

 

 

 

Also, how do I force the user to do the stretch command. If I press enter without selecting anything, it exits the command. I just what it to remain until something is selected or escape to force exit the program.

 

This is my first attempt at some sort of lisp but I'm happy with what this does :)

 

Just one Bug: After finishing command and run an undo the ossnap settings are lost.

 

#|

Modification of original script here by Kiwi Russ

http://forums.autodesk.com/t5/visual...946435#M237968

to work with brick dimensions.

______________________________
HOW TO USE:
Type in number of bricks in X or Y.

9 will move 9 bricks in the X and Y direction.
-9 will move it in the negative X and Y direction.

Choose between:
215mm - this will be used for bricksize only. CO-
225mm - this will be used for bricksize plus one 10mm joint. CO [This is for most stretches you will use, once you have the drawing in brick dims]
235mm - this will be used for bricksize plus two 10mm joints. CO+
Custom - useful to stretch a value times the number of bricks entered.

Script outputs in commandline how far you have strecthed in the X and Y.
______________________________
VERSION HISTORY:
v1.0	26.01.2017	Initial release by 3dwannab
______________________________
KNOWN BUGS:
After finishing command and run an undo the ossnap settings are lost.

|#

(defun c:BRS ( / *error* osmode echo x y pt1 pt2 ss ss1 ss2 a en)

(defun *error* (msg)
	(if (and msg
		(null (member msg '("Function cancelled" "quit / exit abort")))
		)
	(princ (strcat "\nError: " msg))
	)
	(setvar "osmode" osmode)
	(setvar "cmdecho" echo)
	(princ)
	)

(setq osmode (getvar "osmode"))
(setq echo (getvar "cmdecho"))

(prompt "\n X no. of bricks: < 0 >")
(setq x (getstring))

(if (= x "")(setq x "0"))

(cond ((/= x "0")

	(initget "215mm 225mm 235mm Custom")
	(setq ansx (getkword "\nX Brick Size ? [215mm/225mm/235mm/Custom] <225mm>: "))
	(cond
		(
			(= "215mm" ansx)
			(setq x (itosa (* (atoi x) 215)))
			)
		(
			(= "225mm" ansx)
			(setq x (itoa (* (atoi x) 225)))
			)
		(
			(= "235mm" ansx)
			(setq x (itoa (* (atoi x) 235)))
			)
		(
			(= "Custom" ansx)
			(setq x (itoa (* (atoi x) (getint))))
			)
		)
	(if (not ansx) (setq x (itoa (* (atoi x) 225))))
	)
) #| end of cond statement |#

(prompt "\n Y no. of bricks: < 0 > ")
(setq y (getstring))

(if (= y "")(setq y "0"))

(cond ((/= y "0")

	(if (not ansy) (setq ansy "215mm"))

	(initget "215mm 225mm 235mm Custom")
	(setq ansy (getkword "\nY Brick Size ? [215mm/225mm/235mm/Custom] <225mm>: "))
	(cond
		(
			(= "215mm" ansy)
			(setq y (itoa (* (atoi y) 215)))
			)
		(
			(= "225mm" ansy)
			(setq y (itoa (* (atoi y) 225)))
			)
		(
			(= "235mm" ansy)
			(setq y (itoa (* (atoi y) 235)))
			)
		(
			(= "Custom" ansy)
			(setq y (itoa (* (atoi y) (getint))))
			)
		)
	(if (not ansy) (setq y (itoa (* (atoi y) 225))))
	)
) #| end of cond statement |#

(cond ((or (/= x "0") (/= y "0"))

	(setvar "CMDECHO" 0)
	(setvar "osmode" 0)

	(setq A (strcat "@" x "," y))

	(setq PT1 (getpoint "\n Select Entities to Stretch by Crossing Window:"))
	(prompt "\n 1st Point:")
	(setq PT2 (getcorner PT1 "\n 2nd Point:"))

	(prompt "\n Remove Entities..... Add Entities: ")
	(command "Select" "c" PT1 PT2 pause)

	(setq SS (ssget "p"))
	(setq SS1 (ssget "c" PT1 PT2))
	(setq SS2 (ssadd))

	(while( setq EN (ssname SS1 0))
		(if (null (ssmemb EN SS))
			(ssadd EN SS2)
			)
		(ssdel EN SS1)
		)
	(if (< 0 (sslength SS2))
		(command "select" SS2 "" "stretch" "C" PT1 PT2 "R" "P" "" "" A)
		(command "stretch" "c" PT1 PT2 PT1 "" "" A)
		)
	(princ (strcat "\nStretched on X: " x "mm"))
	(princ (strcat "\nStretched on Y: " y "mm"))
	)
(t
	(princ "\nNothing changed.")
	)

)

(*error* nil)

)

 

 

@ BIGAL I didn't quite get you with your post about the side menu? ps AUS bricks are different sizes than EU? Ours are 215mm.

Edited by 3dwannab
Updated code

Share this post


Link to post
Share on other sites
BIGAL

3Dwannab would it not be better to just use the size so you dont have to type mm all the time. If you enter just a size it errors 225=Invalid option keyword

 

 

(initget "215mm 225mm 235mm Custom")
(setq ansy (getkword "\nY Brick Size ? [215mm/225mm/235mm/Custom] <215mm>: "))

(initget "215 225 235 Custom")
(setq ansy (getkword "\nY Brick Size in mm ? [215/225/235/Custom] <215mm>: "))

 

Side menu's were introduced in very early versions of autocad its like having a pop menu that appears and can have various values pre programmed into it. You can imagine it like a pull down menu but it sits on the right hand side of your screen area. You can interact with lisp hence the example I posted where you pick 1 but the lisp gets 215 returned as the answer. It was before toolbars and the menus can call other menus. I will have a Play tomorrow using your values.

Share this post


Link to post
Share on other sites
3dwannab
3Dwannab would it not be better to just use the size so you dont have to type mm all the time. If you enter just a size it errors 225=Invalid option keyword

 

 

(initget "215mm 225mm 235mm Custom")
(setq ansy (getkword "\nY Brick Size ? [215mm/225mm/235mm/Custom] <215mm>: "))

(initget "215 225 235 Custom")
(setq ansy (getkword "\nY Brick Size in mm ? [215/225/235/Custom] <215mm>: "))

It works just fine. Those are just for display proposes. The cond fn for e.g. with:

			(
			(= "Custom" ansx)
			(setq x (itoa (* (atoi x) (getint))))
			)

takes care of that.

 

 

Side menu's were introduced ...ave a Play tomorrow using your values.

Thanks, but I don't think you need to go to any trouble. The list would get very long if it was 20 courses of brick.

 

 

I just want to get rid of the bug where the ossnap var is not sticking if I undo after the command and forcing the user to do the stretch command. if nothings selected. I what it to remain until something is selected or escape to force exit the program.

;)

Share this post


Link to post
Share on other sites

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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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