Author Topic: (challenge) newbie Create a line function .......  (Read 7122 times)

0 Members and 1 Guest are viewing this topic.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
(challenge) newbie Create a line function .......
« on: October 13, 2004, 02:40:49 PM »
This is a challenge for all the newbies out there. Write a function that draws a line based two arguments, point1 and point2. Use the entmake function to create the line.

Bonus:
Write another line function but use ActiveX methods to create the line.
TheSwamp.org  (serving the CAD community since 2003)

daron

  • Guest
(challenge) newbie Create a line function .......
« Reply #1 on: October 13, 2004, 04:47:19 PM »
Most newbie's don't understand how this: (defun newline (point1 point2)...) works. Maybe a way to prime into this would be to write a command using getpoint, then try to develop it into reusable code. Maybe if we get enough (any) participation, someone can help them begin to understand reusability. I personally hope some newbie's will take this challenge.

Come on newbie's.. What are you waiting for: Us to do it?

JohnK

  • Administrator
  • Seagull
  • Posts: 10637
(challenge) newbie Create a line function .......
« Reply #2 on: October 13, 2004, 05:35:41 PM »
...Im working on it, im working on it! *Sheesh!*
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

danny

  • Guest
(challenge) newbie Create a line function .......
« Reply #3 on: October 13, 2004, 07:37:05 PM »
Code: [Select]
(entmake '((0 . "line")
;start point
(10 0.0 0.0 0.0)

ok im lost..

TR

  • Guest
(challenge) newbie Create a line function .......
« Reply #4 on: October 14, 2004, 01:10:55 AM »
I'm lost already.

SMadsen

  • Guest
(challenge) newbie Create a line function .......
« Reply #5 on: October 14, 2004, 05:30:42 AM »
Quote from: danny
Code: [Select]
(entmake '((0 . "line")
;start point
(10 0.0 0.0 0.0)

ok im lost..

Nah, that's an excellent start, Danny. Try finishing the ENTMAKE function first by reading up on it in the help files. You've already supplied the entity type and the start point. For ENTMAKE to create a line it only requires one more piece of information ...

JohnK

  • Administrator
  • Seagull
  • Posts: 10637
(challenge) newbie Create a line function .......
« Reply #6 on: October 14, 2004, 08:32:51 AM »
w00t! your half way there! Keep going.

Is there anything in specific your having a hard time with?
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
(challenge) newbie Create a line function .......
« Reply #7 on: October 14, 2004, 08:43:20 AM »
I agree with Mr. Madsen, that's an excellent start Danny, you're just missing a few bits.

What might help is if you observe the data for an entity that already exists.

Make a line the normal way, that is by typing the line command at the AutoCAD command line. When prompted for the endpoints perhaps key in the coordinates instead of picking them with the mouse (entering coordinates easy to remember).

Then load and run this code little program, selecting the line you just made when prompted.

Code: [Select]
(defun c:ListData ( / myprinc ename )
    (defun myprinc (tabs x)
        (repeat tabs (princ "    "))
        (princ x)
        (princ "\n")
    )
    (cond
        (   (setq ename (car (entsel)))
            (myprinc 0 (strcat "\n" (chr 40)))
            (foreach x (entget ename)
                (myprinc 1 x)
            )
            (myprinc 0 (chr 41))
        )
    )
    (princ)
)

You should see something like this:

Code: [Select]
(
    (-1 . <Entity name: 7ef54e88>)
    (0 . LINE)
    (330 . <Entity name: 7ef54cf8>)
    (5 . 89)
    (100 . AcDbEntity)
    (67 . 0)
    (410 . Model)
    (8 . 0)
    (100 . AcDbLine)
    (10 10.0 10.0 0.0)
    (11 20.0 20.0 0.0)
    (210 0.0 0.0 1.0)
)

What do you notice? Do you see the endpoints you specified?

Some of the data you'll see is not requred to entmake a line, but would be a result of an entmake request; group codes like the -1, 330 and 5 (which you will come to know in time so don't sweat them for now).

Other group codes are the result of default values, that is, you can specifiy their values but if you don't default values are assumeed; group codes like 67, 410, 8 and 210.

So ... what is left? :)

Hope this helps a little.

Cheers, Michael.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

daron

  • Guest
(challenge) newbie Create a line function .......
« Reply #8 on: October 14, 2004, 08:47:53 AM »
Question for the newbie's???
Where can you find much of the dxf (Drawing intereXchange Format) information that you might be able to decipher what (8 . "0") means?

ImaJayhawk

  • Guest
(challenge) newbie Create a line function .......
« Reply #9 on: October 14, 2004, 09:02:26 AM »
Ok I'll give this a try....
Code: [Select]

(defun c:acitvexline ()
  (vl-load-com)
  (setq acadObject   (vlax-get-acad-object))
  (setq mSpace       (vla-get-ModelSpace acadDocument))
  (setq startPt (getpoint "Pick the Start Point"))
  (setq endpt (getpoint "Pick the End Point"))
  (vla-addline mSpace (vlax-3d-point startPt) (vlax-3d-point endPt))
 )



--ImaJayhawk

ImaJayhawk

  • Guest
(challenge) newbie Create a line function .......
« Reply #10 on: October 14, 2004, 09:06:25 AM »
Oops forgot a line...

(defun c:acitvexline ()
  (vl-load-com)
  (setq acadObject   (vlax-get-acad-object))
  (setq acadDocument (vla-get-ActiveDocument acadObject))
  (setq mSpace       (vla-get-ModelSpace acadDocument))
  (setq startPt (getpoint "Pick the start point"))
  (setq endpt (getpoint "Pick the End Point"))
  (vla-addline mSpace (vlax-3d-point startPt) (vlax-3d-point endPt))
 )

--ImaJayhawk

ImaJayhawk

  • Guest
(challenge) newbie Create a line function .......
« Reply #11 on: October 14, 2004, 09:11:13 AM »
Quote from: Daron
Question for the newbie's???
Where can you find much of the dxf (Drawing intereXchange Format) information that you might be able to decipher what (8 . "0") means?


Developer Help File?  The Swamp?




--ImaJayhawk

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
(challenge) newbie Create a line function .......
« Reply #12 on: October 14, 2004, 10:16:08 AM »
Quote from: ImaJayhawk
Ok I'll give this a try....
--ImaJayhawk


That's it, just make it a subroutine that requires two arguments, point1 point2.
TheSwamp.org  (serving the CAD community since 2003)

ImaJayhawk

  • Guest
(challenge) newbie Create a line function .......
« Reply #13 on: October 14, 2004, 10:50:17 AM »
Quote from: Mark Thomas

That's it, just make it a subroutine that requires two arguments, point1 point2.


How about:
Code: [Select]

(defun acitvexline ( startpt endpt / )
  (vl-load-com)
  (setq acadObject   (vlax-get-acad-object))
  (setq acadDocument (vla-get-ActiveDocument acadObject))
  (setq mSpace       (vla-get-ModelSpace acadDocument))
  (vla-addline mSpace (vlax-3d-point startPt) (vlax-3d-point endPt))
 )


Code: [Select]

(setq pt1 '(0 0 0))
(setq pt2 '(1 0 0))
(acitvexline pt1 pt2)





--ImaJayhawk

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
(challenge) newbie Create a line function .......
« Reply #14 on: October 14, 2004, 11:02:13 AM »
Excellent!

How about something like this.

remember to localize your var's
Code: [Select]

(defun acitvexline ( startpt endpt / acadObject acadDocument mSpace)
  (vl-load-com)
  (setq acadObject   (vlax-get-acad-object))
  (setq acadDocument (vla-get-ActiveDocument acadObject))
  (setq mSpace       (vla-get-ModelSpace acadDocument))
  (vla-addline mSpace (vlax-3d-point startPt) (vlax-3d-point endPt))
 )

(defun a-main (/ pt1 pt2 ax_line)

  (while (setq pt1 (getpoint "\nStart Point: "))
(if (setq pt2 (getpoint pt1 "\nEnd Point: "))
 (progn
(setq ax_line (acitvexline pt1 pt2))
(vlax-release-object ax_line)
)
 )
)

  (princ)

  )
TheSwamp.org  (serving the CAD community since 2003)