Jump to content

Initget + getkword string but use real value


Recommended Posts

Posted

Hi everyone,

 

Hopefully the topic here makes sense.

What I am looking to do is probably easy, but I cant think of a logical and efficient way to do this. 

In my code I want to set some variables at the beginning so that I can easily edit them if something changes at some point in the future or I need to add another variables to the list.

This is what I have at the beginning.

(setq jeldwin 1.116 ;Jeldwin has a 3.116" Window Frame
	  brown 0.1875 ;Brown has a 2 3/16" Window Frame
      newmar 1 ;Newmar has a 3" Window Frame. 
      pollard 1.5 ;Pollard has a 3.5" Window Frame
)

 

Later on in the code I want the user to Select the window manufacturer by Name and use initget & getkword and remember the selection so I have this in the code.

  	(if (null Global:WinMan)
	  (setq Global:WinMan "B")
	  )
	(initget "Brown Jeldwin Newmar Pollard")
  	(if (setq win (getkword (strcat "\nWhich window manufacturer [Brown/JeldWin/Newmar/Pollard]<" Global:WinMan "> : ")))
	  (setq Global:WinMan win)
	  )

 

How can I link the Getkword selection with the value of my variables above?

I was thinking about writing a bunch of conditions for doing that, but I would suspect that there must be an easier more efficient way to do this. Plus I dont want to have to add another condition to the code if another Window Manufacturer is added to the list.

Posted (edited)

I found a different method that might work, but I am not that familiar with using mapcar and lambda but I am trying to learn.

 

I found this post by Thwart https://www.cadtutor.net/forum/topic/68302-wcmatch-within-a-list-of-lists/?do=findComment&comment=553307

 

Basically I can create a list of lists at the beginning of my lisp using the code below....

(setq winManLst '(("JeldWin" "1.116")("Brown" "0.1875")("Newmar" "1")("Pollard" "0.6875"))

Then I can use my part of the code that saves my variables

(if (null Global:WinMan)
	(setq Global:WinMan "B"))
	(initget "Brown Jeldwin Newmar Pollard")
(if (setq win (getkword (strcat "\nWhich window manufacturer [Brown/JeldWin/Newmar/Pollard]<" Global:WinMan "> : ")))
	  (setq Global:WinMan win)
	  )

 

After that I can use the code that Thwart posted that is slightly modified and add the variable I need to grab at the end and convert it to an integer. (see below)

 

	(mapcar 
		(function
			(lambda (x)
				(vl-some
					'(lambda (s) (and (wcmatch s Global:WinMan) (setq mlst (cons x mlst))))
					     x
				)
			)
		)
		WinManlst
	)
	(reverse mlst)
(setq WinOffset (atof (cadr (car mlst))))

 

Truth be told though, I have no idea what Thwarts code is actually doing.

I know the (and (wcmatch s Global:WinMan) (setq mlst (cons x mlst) is basically looking to match s (a string) with Global:WinMan (pattern of the string) AND Create a variable called mlst using cons to construct the list. The rest is completely lost to me.

On the plus side this code seems to work great for my needs.

Edited by Strydaris
Posted (edited)

Going the list route using ldata to store your variable into the drawing so when you call it again it remembers what you picked.

 

2 hours ago, Strydaris said:

Truth be told though, I have no idea what Thwarts code is actually doing.

its looking thought "WinManLst" if the first element in the mini list matches win it adds that mini list to another list called mlst

 

All you really need to do is use assoc function like below.

 

(setq winManLst '(( "JeldWin" 1.116) ( "Brown" 0.1875) ( "Newmar" 1.000) ( "Pollard" 0.6875)))
(or (setq win* (vlax-ldata-get "Window" "Manufacturer")) (setq win* "Brown"))  ;if ldata is set will call that fist
(initget "Brown Jeldwin Newmar Pollard")
(setq win (getkword (strcat "\nSet Window Manufacturer: Brown, JeldWin, Newmar, Pollard <" win* ">: ")))
(if win
  (progn ;if user picks a value in getkword it will be set here
    (vlax-ldata-put "Window" "Manufacturer" win)
    (setq WinOffset (cdr (assoc win winManLst)))
  )
  (progn ;if user just uses default it will be set here
    (setq win win*)
    (vlax-ldata-put "Window" "Manufacturer" win)
    (setq WinOffset (cadr (assoc win winManLst)))
  )
)

 

Edited by mhupp
Posted

Like mhupp idea I would make a seperate lisp check for (if (= (vlax-ldata-get "Window" "Manufacturer" ) nil) (load "manufacturer")) so 1 line in any code. The manufacturer.lsp is mhupps code, for me use the Multi radio buttons.lsp to choose manufacturer. Maybe a second defun display value and manufacturer. More values can be saved using Ldata.

Posted
17 hours ago, mhupp said:

Going the list route using ldata to store your variable into the drawing so when you call it again it remembers what you picked.

 

its looking thought "WinManLst" if the first element in the mini list matches win it adds that mini list to another list called mlst

 

All you really need to do is use assoc function like below.

 

(setq winManLst '(( "JeldWin" 1.116) ( "Brown" 0.1875) ( "Newmar" 1.000) ( "Pollard" 0.6875)))
(or (setq win* (vlax-ldata-get "Window" "Manufacturer")) (setq win* "Brown"))  ;if ldata is set will call that fist
(initget "Brown Jeldwin Newmar Pollard")
(setq win (getkword (strcat "\nSet Window Manufacturer: Brown, JeldWin, Newmar, Pollard <" win* ">: ")))
(if win
  (progn ;if user picks a value in getkword it will be set here
    (vlax-ldata-put "Window" "Manufacturer" win)
    (setq WinOffset (cdr (assoc win winManLst)))
  )
  (progn ;if user just uses default it will be set here
    (setq win win*)
    (vlax-ldata-put "Window" "Manufacturer" win)
    (setq WinOffset (cadr (assoc win winManLst)))
  )
)

 

 

Hi @mhupp

 

Not sure I am following what you mean.

I looked up what vlax-ldata-get does and it seems like would save the variable or in my case the selection of the manufacturer type into the CAD file itself.

So if I am correct on this assumption, it would essentially hardcode it directly to the file and anytime I go into that file it would use that manufacturer type or at least be the default selection?

Posted

ldata in this instance is to cut down on mistakes. (opening a drawing at a later date) AutoCAD would remember the manufacture picked back when the command was run and automatically have it set to the default option. rather then always being "Brown" and potentially picking the wrong offset. You could also save the offset value as well.

  • Like 1
Posted

So ldata is transferable from 1 autocad station to another then? It's stored locally in the cad file and will go anywhere the cad file goes regardless of the computer it's on? 

The description says it stores data in a drawing dictionary. 

I just want to make sure I understand fully what it does before I use it. 

Posted

Ohhhh that's a fantastic feature. Why didn't I know about this before. 

Is there any limitations? 

This could open up a lot more automation in the work I do as well as others.

Thanks for bringing this to my attention. 

I love these forums. 

  • Funny 1
Posted
15 minutes ago, Strydaris said:

Is there any limitations?

 

Not that come to mind you can store all types of data  Type: Integer, Real, String, List, Ename (entity name), VLA-object, Variant, Safearray, T, or nil

 

You may also want to check out getenv and setenv. Does basically the same thing ldata does but stores the variable in the computer registry. so it can be called between drawings.

This has a limitations of only being string data can be stored.

 

 

 

 

 

Posted

It's the string values that really come to mind that can help with things. 

We do work for various builders and some of them use different materials or floor joist systems etc. 

Now I'm wondering if I can setup notations within this ldata that can be pulled from to insert a multileaders, then use ldata to fill in the note. 

If I can, this would be fantastic. Only issue would be is, how do I fill up the ldata with all the notations I need. 

Posted
2 hours ago, Strydaris said:

Only issue would be is, how do I fill up the ldata with all the notations I need. 

 

Very simple to do. just like in the lisp you can store a list into the drawing and then call it later to retrieve strings.

Posted (edited)

Think of Ldata as a separate database inside the dwg, you make a database Name then a Key, then a Value. As I posted earlier PUT is 3 items a Get is 2. You can have multiple keys in a Ldata of a single name, I have one with something like 5 values. (vL-Ldata-put "Bigal". Same with pick a manufacturer just have something like my Multi radio buttons displaying various options with current highlighted, it is not documented in the Multi Radio Buttons.lsp but you can set the current button so it matches the default again a LDATA ALANH Key =Radio Value= 3.

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.

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