TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: ELOQUINTET on November 10, 2003, 11:12:18 AM
-
hey guys i'm trying to find a few simple lisps i've seen posted before but can't seem to locate. here's what i want them to do:
1 offset and erase original line
2 draw line between midpoint of two paralell lines
3 mirror objects :basepoint: midpoint between two paralell lines
4 set all colors to bylayer
thanks
dan
-
No.4
(defun cotbyl (obj)
(cond ((= (type obj) 'VLA-OBJECT)
(vlax-put-property obj 'Color acByLayer)
(vlax-release-object obj)
)
)
)
Example:
(setq obj (vlax-ename->vla-object (car (entsel))))
(cotbyl obj)
works with ver. 2000 - 2002
2004 is different.
-
hmmm thanks mark but i'm having some sort of problem. i copied and pasted the code into vlide. when i hit save it said something about. cannot create _.ls file do you want to spool. remember recently i turned off the setting to create a backup. well i said no. when i type "cotbyl" it ays unknown command. so what's happening now? thanks
dan
-
try this one
;;; change selected objects color to 'ByLayer'
;;; ACAD versions 2000-2002
(defun c:c2bl (/ ss parse-ss cotbyl)
(defun parse-ss (ss / cntr ent obj-lst)
(setq cntr 0)
(while
(setq ent (ssname ss cntr))
(setq obj-lst
(cons (vlax-ename->vla-object ent) obj-lst)
cntr (1+ cntr)
)
) ; while
(if obj-lst (mapcar 'cotbyl obj-lst))
) ; defun
(defun cotbyl (obj)
(cond ((= (type obj) 'VLA-OBJECT)
(vlax-put-property obj 'Color acByLayer)
(vlax-release-object obj)
)
)
)
(if (setq ss (ssget))
(parse-ss ss)
)
(princ)
); defun
-
thanks mark that one works great. i nearly paniced whew.
dan
-
Mark,
Let me ask you this....what about MText that has had the color changed in the editor? is there a way to also implement that?
Rug
-
Mark,
Let me ask you this....what about MText that has had the color changed in the editor? is there a way to also implement that?
Rug
yep, but ouch! You're are talking about some work.
-
Hehe hehe hehe....does this mean there is work???? lol Just wanted to double check. :)
Rug
-
hey rugaroo get your own thread :P
dan
-
You said all colors to by layer...well that includes MText too...you just gotta make sure everyone is working hard here lol....Cause honestly I am sick and tired of using the find command to change mtext colors. ;)
Rug
-
1 offset and erase original line
Great for drawing roof overhangs or closet shelves.
;; DrawOffset.lsp
;; Created by C. Alan Butler 2003
;;
;;; Draw a poly line and then offset it.
;;;
;;; THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED
;;; WARRANTY. ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR
;;; PURPOSE AND OF MERCHANTABILITY ARE HEREBY DISCLAIMED.
;;;
;;;
;;
;;
;; error function & Routine Exit
(defun *error* (msg)
(if (not (member msg
'("console break" "Function cancelled" "quit / exit abort")
)
)
(princ (strcat "\nError: " msg))
) ; if
(princ)
) ;
;end error function
;; pre set global variable, it remember your entry
;======================
; Start of Routine
;======================
(defun C:DrawO (/ pt1 pt2 usercmd str en1 en2 )
;;; ------- Some Housekeeping ------------------
(setq usercmd (getvar "CMDECHO"))
(setvar "CMDECHO" 0)
(setvar "PLINEWID" 0)
(setq useros (getvar "osmode")
str "")
(setvar "osmode" 175)
(prompt "/nPick points, Enter when done.")
;;; Draw the pline
(setq pt1 (getpoint))
(command "PLINE" pt1 (Setq pt2 (getpoint pt1))) ;_ COMMAND
(while (setq pt2 (getpoint pt2 "\nNext point: "))(command pt2)) ;_ WHILE
(command "")
(princ)
(setq en1 (entlast))
(initget 1)
(setq pto (getpoint "\nSide to offset:"))
(setq dist (getreal "\nEnter offset distance:"))
(command "_.offset" dist en1 pto "")
;(setq en2 (entlast))
(entdel en1) ; remove the user drawn line
;;;========== Exit Sequence ============
(setvar "osmode" useros)
(setvar "CMDECHO" usercmd)
;;; Exit quietly
(princ)
) ;_end of defun
;;; Notify user program ready to use
(prompt "\n Pline Draw & Offest Loaded: Type 'DrawO' to run it.")
(princ)
-
Don't know what version of cad you're using, but doesn't the express tool, which I believe became a standard tool in 2002, called exoffset already do what you ask and more?
-
that worked great cab thanks. daron i'm working with 2002 and have express. not aware of an exoffset.
dan
-
Try it out. It'll offset the line to the current layer or the source layer. It'll do a multiple offset and it'll do a moving sort of offset. You can also select multiple items to offset using these functions.
-
where do you think it would be. i don't see it in my toolbars pulldown or in my express folder? thanks man
dan
-
This one might help you for No.'s 3 & 4, but you'll have to do a LITTLE bit of the work yourself... :wink:
I added this one to my right click menu definition and put it in my Startup Suite...I use it ALL the time!
I can't remember who gave it to me originally...could have been one of you guys from Cadalog...
(defun c:btwn (/ PT1 PT2)
(setq PT1
(getpoint "\nEnter first point:")
)
(setq PT2
(getpoint "\nEnter second point:")
)
(polar PT1
(angle PT1 PT2)
(/ (distance PT1 PT2) 2)
)
); end btwn.lsp
-
i believe we've had this conversation before or i've seen the post where you got btwn. my question is how would i add this to my right click definition, haven't tried that yet. so if i was to add this then i could do mirror then right click and set my baspoint as midway between 2 paraleel lines. do i understand you correctly. if so help me out with that. thank ya
dan
-
In your menu file, look for
// Begin AutoCAD Pull-down Menus
//
***POP0
**SNAP
and add ID_OsnapBtwn [&Between]_'btwn in there somewhere...I put mine under the Midpoint entry.
Make sure you have that lisp in your startup stuite though so it loads with each drawing.
Give that a try and let me know if that was what you were looking for.
Good Luck,
Mike
-
hey mdub i understand what you're saying but how do i get it so if i start a command like say line that i have osnaps when i right click. right now i just have enter, cancel, pan and zoom. i went to options/right click but it didn't help????
dan
-
where do you think it would be. i don't see it in my toolbars pulldown or in my express folder? thanks man
dan
You can find it in Express->modify->extended offset, or type exoffset. You should be able to see.
-
I think it should work if you only have Windows Standard Accelerator Keys checked.
Try that...??
-
Actually, it might be CTRL+Right Click to get your osnap menu...
-
ah that's it i had remembered i had that in the past but forgot you have to hold down control, got it. thanks
dan
-
mdub i did what you said but it's not showing up in my shortcut menu?
ID_OsnapEndp [&Endpoint]_endp
ID_OsnapMidp [&Midpoint]_mid
ID_Osnapbtwn [&Between]_'btwn
ID_OsnapInte [&Intersection]_int
ID_OsnapAppa [&Apparent Intersect]_appint
ID_OsnapExte [E&xtension]_ext
what's the matter?
dan
-
Did you reload your menu?
If not, be careful! If you've added custom toolbars in AutoCAD (as opposed to adding them to the acad.mnu), you'll lose them unless you copy the definitions from acad.mns to acad.mnu.
Before you try this, save a copy of acad.mns as acadmns.old or something like that...just in case.
-
crap i saved it somewhere else but didn't change the name it blew away everything. i moved the ones i copied back into support and replaced but don't have any of my custom stuff now. i'm not sure if it's worth the time it would time me to recreate it. how can i incorporate this small change without blowing away everything? or recover my old menu file?
dan
-
Dan, Dan, Dan... :cry:
I feel your pain. If you didn't save it in a different diretory, I have some good news and some bad news...
First, the bad:
You're S.O.L. -
**********Stop The Press**********
crap i saved it somewhere else but didn't change the name it blew away everything. i moved the ones i copied back into support and replaced but don't have any of my custom stuff now.
You may be in luck...Now that you've moved the mns file back, open it up and do a search for your toolbars. Search for the name of each. If you find them, COPY THEM INTO YOUR MNU FILE!!!
Doing this will eliminate the possibility of blowing them away in the future.
First of all, have I got everything straight so far?
-
hey when i copied them i didn't see any .mns file. what i copied was the .mnl and .mnr files. i'm kind of screwed but not completely because i have some of this custom stuff done at home i think. is there a better way to do this so in the future i don't get screwed?
dan
-
There IS an MNS file...I'm tellin' ya!
Someone correct me if I'm wrong, but I don't think it's possible NOT to have one.
Anyway, if you want to simply add something to your menu to test, add it to the mns file. When you're confident that it works, go copy it to your mnu file. Make sure you've copied EVERYTHING you've added to the mns. The toolbars you create while in AutoCAD (command: customize) are saved in the mns file which is overwritten by whatever is in the mnu file when you reload it. If your toolbar definitions are copied into the mnu file, you're safe.
NOTE If you use the interface to modify the toolbars, you should cut and paste the modified portions of the MNS file to the MNU file before deleting the MNS file.
I don't think I did a very good job of explaining this...Can someone lend a hand?
-
#2
;;; draw line between midpoint of two paralell lines
(defun midpt (p1 p2)
(mapcar
'(lambda (x y) (/ (+ x y) 2.0)) p1 p2)
)
;
; ,-----------------------------------------------,
; | MAIN FUNCTION |
; '-----------------------------------------------'
;
(defun c:lbmp (/ line1 line2 mpt1 mpt2)
(if (setq line1 (entsel "\nSelect 1st Line: "))
(progn
(setq line1 (entget (car line1)))
(if (setq line2 (entsel "\nSelect 2nd Line: "))
(setq line2 (entget (car line2)))
)
)
)
(if
;; make sure they are both lines
(and
(= (cdr (assoc 0 line1)) "LINE")
(= (cdr (assoc 0 line2)) "LINE")
)
(if
;; make sure they are paralell
(equal
(angle (cdr (assoc 10 line1)) (cdr (assoc 11 line1)))
(angle (cdr (assoc 10 line2)) (cdr (assoc 11 line2)))
)
(progn
(setq mpt1
(midpt (cdr (assoc 10 line1))
(cdr (assoc 11 line1))
)
mpt2
(midpt (cdr (assoc 10 line2))
(cdr (assoc 11 line2))
)
)
;; create the line
(entmake
(list
'(0 . "LINE")
(cons 10 mpt1)
(cons 11 mpt2)
)
)
) ; progn
; else
(prompt "\nLines are not paralell")
) ; if
; else
(prompt "\nOne of the selected entities is not a line")
)
(princ)
)
-
iyiyi i'm hatin life. mark that one didn't work for me. you have any advice on what happened to my menus above. when i close and reopen autocad now none of my menus load. :cry:
dan
-
:oops: :cry:
I'm sorry, Dan...I should have kept my mouth shut! I put you into this situation...I'm gonna try to get you out.
What do you mean by "...none of my menus load"?
In AutoCAD, type MENU at the command prompt. Then find the mnu file and load it. That should give you the basic AutoCAD menu back unless you saved ACAD.mns as ACAD.mnu...I don't know what happens there...
Does this work?
Again, Dan, I'm truly sorry for screwing you up! I will try to make it up to you somehow... :oops:
I should have just told you to add the ID_OsnapBtwn [&Between]_'btwn and left it at that. It would, however be overwritten if you ever reloaded the mnu file....
Let me know...
-
Not been keepin track on the menu topic, but if you unload and/or reload the acad.mns file, everything else goes bye bye and you have to go in and manually reload them. I think .arg files are good at keeping track of them, but that probably won't help you here.
-
yes i can load the menus but if i close acad and reopen they're gone. i have still not been able to find an .mns file. i even did a search in start and nothing. i had tons of custom flyouts and toolbars for my lisps and everything craaaaap.
dan
-
Does anybody else have your custom menu on their machine? Have you ever put it up on a network to move to other machines? Do you have it at a home computer?
-
Dan, I just PM'ed you, please respond.......
-
hmmm i just did a search on a coworkers computer and they have .mns files. why don't i? :cry:
dan
-
daron no noone else has it here unfortunately and it's not on the server. mark what are you saying you pmed me what's that? i thought you meant imed so i opened up my messenger but no?
dan
-
i do have some custom stuff on my computer at home but not everything. guess i should read the creating custom toolbars tutorial huh daron :cry:
dan
-
mark what are you saying you pmed me what's that? i thought you meant imed so i opened up my messenger but no?
dan
On the top of this page look for 'Private Messges'
-
Apparently we lost Dan...............
Dan, just for grins did you check the Recycle Bin?
What ACAD version/OS are you using?
-
Well, I remember when I started using these boards, Cadalog specifically, I had no idea either. I spent a little time selecting links and found out what was to be had. I had to do the same thing with moderating. That's why I put up the thread on it. VBDesign has a huge pdf file on being a moderator. They teach you everything, including what not to do.
-
Well, I guess you guys can enter me into your BAD books. :oops: :cry:
Please let me know if you want me to keep trying to help or if I've done enough damage already.
It won't help, but...I was only trying to help...
Is the directory containing your menu listed in your Support File Search Path?
Regretfully,
Mike
-
no mark just grabbed lunch i'm here now responded to your message
dan
-
back to the drawing board :( thanks for trying to help mdub
dan
-
Well, where are you now?
Does AutoCAD still load without a menu?
Try going into Options>Files (tab). Expand Menu, Help, and Miscellaneous File Names, then Menu File. What does it say?
This (from AutoCAD Help File) may be of some assistance in the future...(?)
MNU: Template menu file.
MNC: Compiled menu file. This binary file contains the command strings and menu syntax that defines the functionality and appearance of the menu.
MNR: Menu resource file. This binary file contains the bitmaps used by the menu.
MNS: Source menu file (generated by AutoCAD).
MNT: Menu resource file. This file is generated when the MNR file is unavailable, for example, read-only.
MNL: Menu LISP file. This file contains AutoLISP expressions that are used by the menu file and are loaded into memory when a menu file with the same file name is loaded.
-
i spoke with mark on the phone but sadly i have to start over. will use marks custom menu tutorial this time :oops:
dan
-
Alright...
I'll leave it with I'm Sorry...
:oops:
I thought I ...never mind
Good Luck!
-
sawright mdub if you don't try you can't fail
or succeed
dan
-
True enough...
On the bright side, you'll probably never let this happen to you again. Losing lots of custom additions to your menu leaves a bad tastes in ones mouth!
Since you're doing a tutorial, is there something in there about creating a partial menu? That's what I use...I only keep my custom stuff in there. The rest of the AutoCAD funtionality comes from the plain ol' Acad.mnu for the most part...
-
My company has implemented user loginname menufiles (.mns and .mnl) and profiles (.arg) and placed them on the network. This way they load on any machine you log into. Any custom tools get created in them.
-
Mark,
FYI
I have had problems with a similar algorithms where the lines were parallel but they
were drawn from opposite directions and failed the test. So i had to add code to swap
ends on one of the lines. Also had trouble with lines being exactly parallel,
in that the angles did not match exactly. I had to use the fuss factor in the EQUALS
function. I would hope these were unusual cases but they existed in several
drawings I inherited.
CAB
-
Thanks for the info CAB, changing program as we speek........