Author Topic: Help with snippet of code  (Read 7668 times)

0 Members and 1 Guest are viewing this topic.

mbdoyle

  • Guest
Help with snippet of code
« on: September 09, 2010, 04:35:40 PM »
Hello all. I was wondering if anybody could assist me with the following little piece of code:

/////////////////////////////////////////////////////////////////////////////
(defun C:cor (/ l1 l2 l3 l4)
(setq l1(entsel "\nPick first line")
     l2(entsel "\nPick second line")
     l3(entsel "\nPick third line")
     l4(entsel "\nPick fourth line"));
(command "chamfer" "a" ".75" "90" "u" "l1" "l3" "l2" "l4" )
  )
/////////////////////////////////////////////////////////////////////////////

I have attached an example of what I would like this code to accomplish. Basically I'm trying to run the chamfer command but instead of getting prompted to select lines inside of the command I'm trying to have those entities(l1, l2, l3, l4) chosen outside of it then running the command with the entities substituted for the "Pick line" prompts. I hope that explanation was clear but if it wasn't please look @ the attached example.

Also I was wondering why the prompts change in the Chamfer command for example; why is the getkword multiple option Multiple when chamfer is typed from the command line and then mUltiple from the (command "chamfer" ....) is used in a lisp routine?

As you can probably tell, I'm pretty new to programming(and posting on this forum), so any clarification  I could get would be greatly appreciated. :-)
 
Thanks,
Matt





 
« Last Edit: September 09, 2010, 04:42:41 PM by mbdoyle »

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Help with snippet of code
« Reply #1 on: September 09, 2010, 04:39:51 PM »
There is a lot to be done to the code as far as error trapping goes, but one step in the right direction would be to take the quotation marks away from the "l1" "l2" etc...

mbdoyle

  • Guest
Re: Help with snippet of code
« Reply #2 on: September 09, 2010, 04:56:24 PM »
Wow that had to be the fastest reply ever. I took the quote marks away, but it still won't run properly. I know there isn't any error trapping, but I'm just trying to make it work in a simple example first. Is the (command "chamfer") line wrong?

(defun C:cor (/ l1 l2 l3 l4)
(setq l1(entsel "\nPick first line")
     l2(entsel "\nPick second line")
     l3(entsel "\nPick third line")
     l4(entsel "\nPick fourth line"));
(command "chamfer" "a" ".75" "90" "u" l1 l3 l2 l4 )
  )

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Help with snippet of code
« Reply #3 on: September 09, 2010, 05:00:31 PM »

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Help with snippet of code
« Reply #4 on: September 09, 2010, 05:00:45 PM »
What does this return (entsel "\nPick first line") You might need to jump in the CAR and go for a ride down add a function lane  :-) (car (entsel))

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Help with snippet of code
« Reply #5 on: September 09, 2010, 06:03:37 PM »
Give this a try:

Code: [Select]
(defun c:test (/ chm chd chc)
  (setq chm (getvar 'chammode))
  (setq chd (getvar 'chamferd))
  (setq chc (getvar 'chamferc))
  (setvar 'chammode 1)
  (setvar 'chamferd (angtof "90"))
  (setvar 'chamferc 0.75)
  (command "_.chamfer" "U")
  (while (> (getvar 'cmdactive) 0) (command pause))
  (setvar 'chammode chm)
  (setvar 'chamferd chd)
  (setvar 'chamferc chc)
  (princ)
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

mbdoyle

  • Guest
Re: Help with snippet of code
« Reply #6 on: September 10, 2010, 10:15:06 AM »
Give this a try:

Code: [Select]
(defun c:test (/ chm chd chc)
  (setq chm (getvar 'chammode))
  (setq chd (getvar 'chamferd))
  (setq chc (getvar 'chamferc))
  (setvar 'chammode 1)
  (setvar 'chamferd (angtof "90"))
  (setvar 'chamferc 0.75)
  (command "_.chamfer" "U")
  (while (> (getvar 'cmdactive) 0) (command pause))
  (setvar 'chammode chm)
  (setvar 'chamferd chd)
  (setvar 'chamferc chc)
  (princ)
)

  Ron's code works and it does what I showed in my example, however I need it to work in a certain way, specifically I'm trying to get this code to read line entities into (command “._chamfer”). I know that I'm prompting the user to select  four lines in my code example, but that will change later on as this little bit of code is part of a larger program. My real aim here is to figure out how to pass line entity values into the chamfer command as arguments without prompting the user to select lines from within the command(if that is even possible). I hope that makes sense. I'm sorry that I wasn't more clear on that before. :oops:

Matt   

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Help with snippet of code
« Reply #7 on: September 10, 2010, 11:38:12 AM »
This seems to pass the lines to chamfer:

Code: [Select]
(defun c:test (/ chm chd chc l1 l2)
  (setq chm (getvar 'chammode))
  (setq chd (getvar 'chamferd))
  (setq chc (getvar 'chamferc))
  (setvar 'chammode 1)
  (setvar 'chamferd (angtof "90"))
  (setvar 'chamferc 0.75)
  (setq l1 (car (entsel))
l2 (car (entsel))
  )
  (command "_.chamfer" "Multiple" l1 l2 "")
  ;;(while (> (getvar 'cmdactive) 0) (command pause))
  (setvar 'chammode chm)
  (setvar 'chamferd chd)
  (setvar 'chamferc chc)
  (princ)
)
« Last Edit: September 10, 2010, 12:28:07 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Help with snippet of code
« Reply #8 on: September 10, 2010, 11:43:29 AM »
Is the "U" supposed to be Multiple? For me (v2009), it's undo.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

mbdoyle

  • Guest
Re: Help with snippet of code
« Reply #9 on: September 10, 2010, 12:00:46 PM »
Is the "U" supposed to be Multiple? For me (v2009), it's undo.

That's a part of what I asked in my original question. When you type chamfer from the command line, U is for undo but when you write it as (command "._chamfer" ...) the "u" is for mUltiple, and I have no idea why.

BTW thank you Ron that was what i was trying to do with l1, l2, etc. One stupid question though; does the "select line" prompt come from within the chamfer command itself? 

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Help with snippet of code
« Reply #10 on: September 10, 2010, 12:03:25 PM »
Is the "U" supposed to be Multiple? For me (v2009), it's undo.

That's a part of what I asked in my original question. When you type chamfer from the command line, U is for undo but when you write it as (command "._chamfer" ...) the "u" is for mUltiple, and I have no idea why.

BTW thank you Ron that was what i was trying to do with l1, l2, etc. One stupid question though; does the "select line" prompt come from within the chamfer command itself? 
That's why it's best to ALWAYS spell it out.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Help with snippet of code
« Reply #11 on: September 10, 2010, 12:16:35 PM »
Is the "U" supposed to be Multiple? For me (v2009), it's undo.

Did you try out the last "test" function?

For me:

Quote
LISP ROUTINE
Select object: _.chamfer
(TRIM mode) Current chamfer Length = 0'-0 3/4", Angle = 90
Select first line or [uNdo/Polyline/Distance/Angle/Trim/Method/mUltiple]: U
Select first line or [uNdo/Polyline/Distance/Angle/Trim/Method/mUltiple]:
Select second line or shift-select to apply corner:
Select first line or [uNdo/Polyline/Distance/Angle/Trim/Method/mUltiple]:

COMMAND
Command: chamfer
(TRIM mode) Current chamfer Length = 0'-0 3/4", Angle = 90
Select first line or [Undo/Polyline/Distance/Angle/Trim/mEthod/Multiple]:

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Help with snippet of code
« Reply #12 on: September 10, 2010, 12:17:49 PM »
Is the "U" supposed to be Multiple? For me (v2009), it's undo.

Did you try out the last "test" function?

For me:

Quote
LISP ROUTINE
Select object: _.chamfer
(TRIM mode) Current chamfer Length = 0'-0 3/4", Angle = 90
Select first line or [uNdo/Polyline/Distance/Angle/Trim/Method/mUltiple]: U
Select first line or [uNdo/Polyline/Distance/Angle/Trim/Method/mUltiple]:
Select second line or shift-select to apply corner:
Select first line or [uNdo/Polyline/Distance/Angle/Trim/Method/mUltiple]:

COMMAND
Command: chamfer
(TRIM mode) Current chamfer Length = 0'-0 3/4", Angle = 90
Select first line or [Undo/Polyline/Distance/Angle/Trim/mEthod/Multiple]:
How odd, I get the same thing. Precisely why I made my previous suggestion.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Help with snippet of code
« Reply #13 on: September 10, 2010, 12:22:59 PM »
But that makes too much sense!  :-D

*change made above
« Last Edit: September 10, 2010, 12:27:19 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Help with snippet of code
« Reply #14 on: September 10, 2010, 12:23:39 PM »
But that makes too much sense!  :-D
Oh yeah. :lol:
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox