Author Topic: line with attribute tool  (Read 10137 times)

0 Members and 1 Guest are viewing this topic.

dubb

  • Swamp Rat
  • Posts: 1105
line with attribute tool
« on: November 10, 2004, 12:30:01 PM »
im looking for a tool that will draw a line on layer S-BEAM between two points and offset each end point -3". and then inserts a text attribute on layer S-TEXT  at the middle of the line. so in the end the attribute and the line are not related.

this will be used to draw a beam between two points and have attribute (text) in the middle top of the beam.  I dont know if there is something out there like this but if there is a similar post please link me.



the whole end product will look like this only the end points of this beam is offset by 3" from each end
|   ____BM-1______    |

CADaver

  • Guest
line with attribute tool
« Reply #1 on: November 10, 2004, 01:04:25 PM »
Go ahead and make the attempt tp write the pseudo-code for what you're trying to do.  I am sure one of the great-guru-code-gods here will help you flesh it out as you go.

dubb

  • Swamp Rat
  • Posts: 1105
line with attribute tool
« Reply #2 on: November 11, 2004, 01:42:48 PM »
ok. since im a totall NeWB to lisp....ill be referring to the afra lisp guide so ill be back in a while with my first crack at this routine...are there certain codes or variables to take into consideration?

daron

  • Guest
line with attribute tool
« Reply #3 on: November 11, 2004, 01:50:33 PM »
First thing to do is spell out how you would do this by hand. That's how we start pseudo-code.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
line with attribute tool
« Reply #4 on: November 11, 2004, 02:20:39 PM »
dubb
Daron gives good advice.
You may think its too simple a problem to write the steps down but it's the best place to
start. I may not write the code down but I do it in my head for simple problems.

Here I'll get you started.

1 Change layer to S-BEAM, assume it exist for the time being
2 ask user to pick end point of line
3 as user to pick other end of line

You take it from here. How would you actually draw this?
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.

dubb

  • Swamp Rat
  • Posts: 1105
line with attribute tool
« Reply #5 on: November 11, 2004, 02:42:19 PM »
Quote
How would you actually draw this?


its relatively simple. i draw a line from one end point to another end point then i stretch each end 3" less than. and then i insert and attributed that is centered on top of the line. thats it. i can write the code for picking the line points and inserting the attribute. but i dont think i can get the lines to stretch 3" less on each side.


so far i started writing this but i havent finished yet. i guess im stuck and im looking for more code content to use.

Code: [Select]

(defun c:beam ()


(setq pt1 (getpoint "\nPick First Beam Point:"))
;comment here

(setq pt2 (getpoint "\nPick Second Beam Point:"))
;comment here
(command "LINE" pt1 pt2 "")
;draw the line

(princ)
;clean running
) ;end defun

(princ)
;clean loading

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
line with attribute tool
« Reply #6 on: November 11, 2004, 02:53:48 PM »
Try this in your code (remove the (command "line") part of yours first.
Code: [Select]

(setq newpt1 (polar pt1 (angle pt1 pt2) 3))
(setq newpt2 (polar pt2 (angle pt2 pt1) 3))
(entmake (list '(0 . "LINE")
      (cons 10 newpt1)
      (cons 11 newpt2)
      )
)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
line with attribute tool
« Reply #7 on: November 11, 2004, 02:54:24 PM »
Here are some tools for you.
(setq ang  (angle pt1 pt2))
(setq newpt1 (polar pt1 ang 3))
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.

dubb

  • Swamp Rat
  • Posts: 1105
line with attribute tool
« Reply #8 on: November 11, 2004, 04:12:12 PM »
thanks it now draws the line for me. how come i cant see the line as i use the routine. i see the line after the routine is done.

what does
Quote
ang
do?

what does
Code: [Select]
(setq ang (angle pt1 pt2)) do?

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
line with attribute tool
« Reply #9 on: November 12, 2004, 07:38:59 AM »
ang is the variable that holds the angle pt1 pt2 and (angle pt1 pt2) if the function
that returns that angle. So to take it a step further you can use:
(setq ang1 (angle pt1 pt2)) ; angle of line FROM pt1 to pt2
(setq ang2 (angle pt2 pt1)) ; angle of line FROM pt2 to pt1

Now you know the angle from the picked points toward the new points you want to draw the
line from. You can use the POLAR function to get the new points. In your case 3 units
distance from the picked points. Polar works like this:
(setq newpt1 (polar pt1 ang1 3)) ; newpt1 is 3 units from pt1 toward pt2
you don't need pt1 any more so you could reuse the variable like this:
(setq pt1 (polar pt1 ang1 3)) ; pt1 assigned a new location

By doing the same thing with pt2 you can draw your line.
(setq pt2 (polar pt1 ang1 3)) ; pt2 assigned a new location
(command ".line" pt1 pt2 "")

Or you can use the results of (polar pt1 ang1 3) directly without
reassigning pt1. Like this:
(command ".line" (polar pt1 ang1 3) (polar pt1 ang1 3) "")

As Jeff pointed out you can use ENTMAKE to create the line as well as the command I used.
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.

daron

  • Guest
line with attribute tool
« Reply #10 on: November 12, 2004, 08:07:53 AM »
Quote from: dubb
thanks it now draws the line for me. how come i cant see the line as i use the routine. i see the line after the routine is done.



(defun c:beam ()

Code: [Select]

(setq pt1 (getpoint "\nPick First Beam Point:")
        pt2 (getpoint "\nPick Second Beam Point:"))


^your code cleaned up a bit^^^
vYour code with one additionvvv

Code: [Select]

(setq pt1 (getpoint "\nPick First Beam Point:")
        pt2 (getpoint pt1 "\nPick Second Beam Point:"))


Note the placement of pt1 just after getpoint in the second variable.
This will draw a rubberbanding line. Also, look into initget for error control and grdraw for line drawing.

dubb

  • Swamp Rat
  • Posts: 1105
line with attribute tool
« Reply #11 on: November 15, 2004, 11:54:32 AM »
Quote

ang is the variable that holds the angle pt1 pt2 and (angle pt1 pt2) if the function
that returns that angle. So to take it a step further you can use:
(setq ang1 (angle pt1 pt2)) ; angle of line FROM pt1 to pt2
(setq ang2 (angle pt2 pt1)) ; angle of line FROM pt2 to pt1

Now you know the angle from the picked points toward the new points you want to draw the
line from. You can use the POLAR function to get the new points. In your case 3 units
distance from the picked points. Polar works like this:
(setq newpt1 (polar pt1 ang1 3)) ; newpt1 is 3 units from pt1 toward pt2
you don't need pt1 any more so you could reuse the variable like this:
(setq pt1 (polar pt1 ang1 3)) ; pt1 assigned a new location

By doing the same thing with pt2 you can draw your line.
(setq pt2 (polar pt1 ang1 3)) ; pt2 assigned a new location
(command ".line" pt1 pt2 "")



thanks, it now seems clear for me. i have to go back and rework the routine.

Quote

Code:

(setq pt1 (getpoint "\nPick First Beam Point:")
        pt2 (getpoint pt1 "\nPick Second Beam Point:"))
 


Note the placement of pt1 just after getpoint in the second variable.
This will draw a rubberbanding line. Also, look into initget for error control and grdraw for line drawing.


wow that simple change makes a difference

ok...if there are any more advice, keep them coming if you liked to post. ill be working on this routine ill be back on this topic after ive developed the routine. thanks guys

dubb

  • Swamp Rat
  • Posts: 1105
line with attribute tool
« Reply #12 on: December 02, 2004, 03:52:08 PM »
OK, im back on this thread again. sorry it took so long. ive made a few changes to the code i previously had.
Code: [Select]

(defun c:bm ()
(setq pt1 (getpoint "\nPick First Beam Point:")
        pt2 (getpoint pt1 "\nPick Second Beam Point:"))
;comment here
(command "clayer" "s-beam")
(setq newpt1 (polar pt1 (angle pt1 pt2) 3))
(setq newpt2 (polar pt2 (angle pt2 pt1) 3))
(setq pt3 (polar pt1 (angle pt1 pt2) 5))
(entmake (list '(0 . "LINE")
          (cons 10 newpt1)
          (cons 11 newpt2)
 
          )
    )
(command "clayer" "s-bm-text")
(COMMAND "-insert" "BM-TEXT" pt3 "" "" "")

(princ)
) ;end defun



the problem with this one is i cant specify "PT3" to be the midpoint of pt1 and pt2 at the angle of pt1 and pt2. and i cant get  s-bm-text layer in the drawing without having it created first.

whdjr

  • Guest
line with attribute tool
« Reply #13 on: December 02, 2004, 04:04:42 PM »
dubb,

First things first.  All the variables you have established (ie. pt1, pt2, ang, etc.) need to be localized so as not to interfere with other programs.  Here is some info to get you started on figuring out how to localize them.

Quote
The following example shows the use of local variables in a user-defined function (be certain there is at least one space between the slash and the local variables).

_$  (defun LOCAL ( / aaa bbb)
(_> (setq aaa "A" bbb "B")
(_> (princ (strcat "\naaa has the value " aaa ))
(_> (princ (strcat "\nbbb has the value " bbb))
(_> (princ) )

LOCAL

Before you test the new function, assign variables aaa and bbb to values other than those used in the LOCAL function.

_$  (setq aaa 1 bbb 2)

2

You can verify that the variables aaa and bbb are actually set to those values.  

_$  aaa
1
_$  bbb

2

Now test the LOCAL function.

_$  (local)
aaa has the value A

bbb has the value B

You will notice the function used the values for aaa and bbb that are local to the function. You can verify that the current values for aaa and bbb are still set to their nonlocal values.

_$  aaa
1
_$  bbb

2

In addition to ensuring that variables are local to a particular function, this technique also ensures the memory used for those variables is available for other functions.


Please ask more questions if this doesn't make sense.

dubb

  • Swamp Rat
  • Posts: 1105
line with attribute tool
« Reply #14 on: December 02, 2004, 04:26:24 PM »
huh?....it kinda blew right past me. you mean to say that the way i arranged my code is improper? pt1 and pt2 dont interfere with other routines that i have loaded is there a way to determine it absolutely will interfere?