Author Topic: trying to write my first lisp and i need a bit of help  (Read 23558 times)

0 Members and 1 Guest are viewing this topic.

ELOQUINTET

  • Guest
trying to write my first lisp and i need a bit of help
« on: July 26, 2005, 10:16:14 AM »
i think i should explain what i'm trying to acheive. we have a custom program for drawing our shade elevations but once they are drawn they are not really that friendly to do little tweaks to. when i need to stretch the elvation i don't want to have to go back through the dialogue and redraw it. one of the really annoying things is we have abbreviations for shadecloth (s.c.) and shade opening width (s.o.w.) but you will see in my example that when you stretch the elevation they don't stay centered. i have been using tracking to move them but it would be nice to be able to have a lisp do it for me.

here's basically what i'm trying to do:
pick the text using the node as the point
then move the text to the midpoint of the dimension line
then move the text down 3-1/2

see lisp and image below:

take it easy on me guys remember this is my first try  :oops:




Code: [Select]
(defun C:mto ()
  (setq p1 (getpoint "pickpoint-1"));\;
  (setvar "osmode" 2)
  (setq p2 (getpoint "pickpoint-2"));\;
  (command "move" p1 p2)
  (command "move" "p" @ 3.5))
  (setvar "osmode" 127)
  (princ)
  )




ELOQUINTET

  • Guest
trying to write my first lisp and i need a bit of help
« Reply #1 on: July 26, 2005, 10:48:30 AM »
maybe i am trying to write this too much like a macro. the idea originated from a macro we have for doing something else, gotta start somewhere  :roll:

daron

  • Guest
trying to write my first lisp and i need a bit of help
« Reply #2 on: July 26, 2005, 11:04:16 AM »
You could just grab the text like this
(entget (car (entsel)))
That will give you a list of dxf info in the text.
You'll need to set up variables. One for the above and one for the ename of the object:
(car (entsel))
Then you need to find out if the text justification is > 0. Is (73 . 0) and (72 . 0). Depending on your findings, you'll need to change group code 10 or 11.
You can use mapcar and a list:
(mapcar '- (list 0.0 3.0 0.0) (cdr (dxf code 11)))
Substitute its results into the list using
(subst newlist oldlist elist)
Then make the mod hold
(entmod (above subst))
(entupd ename)
Try a couple of these things out.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
trying to write my first lisp and i need a bit of help
« Reply #3 on: July 26, 2005, 11:15:31 AM »
Wow, wouldn't it be better to modify the dimension to include the text?
Just over ride the text with this. <>\XS.O.W.
Then stretch to your hearts content.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ELOQUINTET

  • Guest
trying to write my first lisp and i need a bit of help
« Reply #4 on: July 26, 2005, 11:27:53 AM »
yes i agree cab and it is my intention to greatly improve this routine once i am capable. there are many shortcomings of it. another being that there is no option to not include the detail callouts because sometimes i have to piece a long elevation together. or the option to draw a long elevation would be great. and to be prompted for the beginning detail number and it would increment them left to right and the sheet number. the thought was good but now its time to expand it. daron you completely lost me. i'll read about the functions you mentioned and see if i can put something together thanks guys

daron

  • Guest
trying to write my first lisp and i need a bit of help
« Reply #5 on: July 26, 2005, 11:29:42 AM »
I was thinking the same thing, but he's trying to learn lisp here. Shant we work with him with what he'd like to do. Sure, it's not to hard to program dimension mods either. Maybe Dan could write both, one at a time, of course.

ELOQUINTET

  • Guest
trying to write my first lisp and i need a bit of help
« Reply #6 on: July 26, 2005, 11:44:35 AM »
some of the functions look familiar but i havent a clue how to figure out what youre asking me to figure out. heres what i have now. i can already use mark dimension override lisp to add whatever override i desire but i wanted to try to write something i would find useful but maybe this is too complicated for my first try what do ya think?  :oops:

Code: [Select]
(defun C:mto ()
(entget (car entsel)))
(mapcar '- (list 0.0 3.0 0.0) cdr (dxf code 11)))
(subst newlist oldlist elist)
(entmod (above substr))
(entupd ename)
(princ)

ELOQUINTET

  • Guest
trying to write my first lisp and i need a bit of help
« Reply #7 on: July 26, 2005, 11:45:55 AM »
i'm only on lesson 3 of stigs tutorial keep in mind  :oops:

daron

  • Guest
trying to write my first lisp and i need a bit of help
« Reply #8 on: July 26, 2005, 12:14:04 PM »
Dan, I purposely left out variables and actual working things for your benefit. If you leave it as is, this is what you end up with:
mto
user selects object. Nothing remembered.
mapcar crashes because cdr is not a list.
The rest of the routine dies.

Look into setq
Start off with (setq varname (entsel "\nPick something: "))
In the vlide, type that, then highlight it and pick the little microscope button.
Then try this:
(setq ename (car varname))
You should end up with a mostly useless block.
Next try:
(setq elist (entget ename))
This will return a list that has lots of information in it. Under the help files, look for the dxf area and find text. There you'll see lots of definitions for what the first number means as well as what the second items mean. You'll be looking for 10, 11, 72 and 73.
When you get a handle on that, we'll look into what mapcar can do for you or if we should even be using it.

ELOQUINTET

  • Guest
trying to write my first lisp and i need a bit of help
« Reply #9 on: July 26, 2005, 01:02:54 PM »
daron heres what i have so far. it appears to me to be code 72. thanks for helpin out giving me hints. like you say doing is the only way to really learn this. i'm trying but you may have to hold my hand for awhile until the light clicks on. thanks for your patience

Code: [Select]
(defun C:mto (shade)
(setq varname (entsel "\nPick something: "))
(1020.19 934.72 0.0)) ;;when i inspected the above line i got this?
(setq ename (car varname))
(setq elist (entget ename))

(mapcar '- (list 0.0 3.0 0.0) cdr (dxf code 72)))
(subst newlist oldlist elist)
(entmod (above substr))
(entupd ename)
(princ)

ELOQUINTET

  • Guest
trying to write my first lisp and i need a bit of help
« Reply #10 on: July 26, 2005, 01:18:54 PM »
i have a side question. i want to print out all of my lisps i've collected and gothrough and study them. i'm wondering what's the easiest way to print out all of the file in a folder. i remeber seeing something but cant remember right now?

daron

  • Guest
trying to write my first lisp and i need a bit of help
« Reply #11 on: July 26, 2005, 01:22:27 PM »
Dan, when you inspect entsel by itself, you should get:
Code: [Select]
(<Entity name: 7eb06630> (1214.74 383.699 0.0))
The car is the Entity name and the cadr or cdr is the coordinates of pick point of the selection. This point is useless for your purposes.
What you want to get is the car of that entsel list, which still does nothing for you except give you readable information. When you collect the car of entsel, get the entity list -> entget. So, you need:
(setq varname (car (entsel "\Pick something: ")))
and
(setq elist (entget varname)).

Really, you should use something better than varname, like ename, since what you're collecting is and Entity NAME, which you'll need in order to update your object (entity).

Your mapcar is still not quite correct. Let's not work on that yet, but for extra credit, read the help file on mapcar and see if you can find why it'll fail as it's written. Oh, and the first line:
(defun c:mto (shade)
Shade will do nothing for you at this time and if shade were to become a variable you need to put (/ shade) like that. You'll get into (shade)'s later. They can be confusing to discuss when you don't need them. Leave it empty () at this point or put (/ all variable names) like that, as you create variable names.

As far as the hand holding goes, I believe we've all been waiting for this day. I'm sure I'm not the only one that needed some hand holding when I started learning this stuff. However, if I wasn't working out little pieces at a time as I went, I'd have never learned anything.

ELOQUINTET

  • Guest
trying to write my first lisp and i need a bit of help
« Reply #12 on: July 26, 2005, 01:50:28 PM »
Code: [Select]
(defun C:mto ();;when i inspect to here i get USUBR@0d01a848 C:MTO> {name} "C:MTO" <flags> {} why???
(setq ename (entsel "\nPick something: "))
;;when i inspected the above line alone i got this for the entity name:7ef377a0
(setq ename (car ename))
(setq elist (entget ename))
(mapcar '-3 (list 0.0 3.0 0.0) cdr (dxf code 72)))



extra credit:
does the mapcar problem have to do with this

(mapcar '-

doesnt there need to be a value there?

the examples i see for mapcar don't appear the same as this to me

daron

  • Guest
trying to write my first lisp and i need a bit of help
« Reply #13 on: July 26, 2005, 02:21:30 PM »
Why what? Open and closed parens? We'll delve into that another time.
If that's not the question, I'll answer another: Why, USUBR? Because once loaded, your DEfined FUNction (defun) becomes a User-defined SUBRoutine.
Let's get you understanding what different functions do first.
What do you get when you inspect:
(setq ename (car ename))?
What do you get when you inspect;
(setq elist (entget ename))?

As far as the extra credit goes, try this:
(mapcar '- '(10 5 2) '(2 5 10))
Here's what help has to say:
Quote
(mapcar function list1... listn)

Arguments

function

A function.

list1... listn

One or more lists. The number of lists must match the number of arguments required by function.

In our sample, is not '- a function?
This is how it should be written:
(mapcar '- (list 0.0 3.0 0.0) (cdr (dxf code from elist here))).
Let's ignore that for now. I put it up there to ease the strain on your mind. We'll get to it soon enough.

ELOQUINTET

  • Guest
trying to write my first lisp and i need a bit of help
« Reply #14 on: July 26, 2005, 02:56:11 PM »
i am reading through stigs tutorial so i'm sure i'll gain a better understanding as i progress. i've learned alot already. my problem is following the chain of command so to speak because the strucutre keeps changing. i am getting confused on what to analyze first, second, third and so on. i guess that comes with practice (and many hours of banging my head against my desk). here's what i have now but am not sure what to do with the end bits?


Code: [Select]
(defun C:mto ()
(setq ename (entsel "\nPick something: "))
;;when i inspected the above line alone i got this for the entity name:7ef377a0
(setq ename (car ename))
(setq elist (entget ename));;when i inspect this i see a bunch of info. is this it: [22] (73.0)
(mapcar '- (list 0.0 3.0 0.0) (cdr (dxf code 73.0)))
(subst newlist oldlist elist)
(entmod (above substr))
(entupd ename)
(princ)