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

0 Members and 1 Guest are viewing this topic.

ImaJayhawk

  • Guest
(challenge) newbie Create a line function .......
« Reply #15 on: October 14, 2004, 12:33:54 PM »
Are there any other ways using activex?  :obsessed:



--ImaJayhawk

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
(challenge) newbie Create a line function .......
« Reply #16 on: October 14, 2004, 12:36:42 PM »
Quote from: ImaJayhawk
Are there any other ways using activex?  :obsessed:...


yep.  See this: "getpoint" Try to find the ActiveX equilivant for that.

Then we can move on from there.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

ImaJayhawk

  • Guest
(challenge) newbie Create a line function .......
« Reply #17 on: October 14, 2004, 05:19:11 PM »
Ok took a little research.....

Code: [Select]

(defun activexline ( 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))
  (setq util (vla-get-utility acadDocument))
  (vla-addline mSpace startpt endPt)
 )

(defun a-main (/ pt1 pt2 ax_line)
   (while  (setq pt1 (vla-getpoint util nil "\nSpecify First Point : "))
   (if (setq pt2 (vla-getpoint util pt1 "\nSpecify Second Point : "))
     (progn
      (setq ax_line (activexline pt1 pt2))
      (vlax-release-object ax_line)
      )
     )
   )

  (princ)

  )



Not sure I understand the syntax for vla-getpoint or what
(setq util (vla-get-utility acadDocument)) does.  
 :?:


--ImaJayhawk

csgoh

  • Newt
  • Posts: 176
(challenge) newbie Create a line function .......
« Reply #18 on: October 15, 2004, 05:29:03 AM »
Code: [Select]

  (setq acadObject   (vlax-get-acad-object))
  (setq acadDocument (vla-get-ActiveDocument acadObject))
  (setq mSpace (vla-get-ModelSpace acadDocument))
  (setq util (vla-get-utility acadDocument))

What are these 4 lines for???
Looking at the codes, these 4 variables are nout used at all. Or do we have do define it everytime we use ActiveX???

SMadsen

  • Guest
(challenge) newbie Create a line function .......
« Reply #19 on: October 15, 2004, 07:26:23 AM »
All variables are used in the code. Objects are ordered in a hierarchial manner, which means that in order to access a particular object you often need to query several objects.

At the first line, the parent of all objects within AutoCAD is accessed; it's the application itself. The next line queries the application object in order to retrieve the active document. This object is always present as a child of the application but is assigned on the fly to point to the active document. It corresponds to the ThisDrawing object in VBA.

As the purpose of the routine is to draw a line, it needs to access a drawing area where a line can be drawn. A document object holds a number of child objects in itself, one of which is the modelspace drawing area. Of course, it's not literally an "area" but simply a collection of graphical objects such as lines and circles etc. So before a line can be added, the routine needs to query the active document to get hold of the modelspace object.

Except for the very first function that retrieves the application, notice that the queried object is always given as the first argument to a VLA function.

The 4th object is one that gives access to user interface functions. They are (typically) ActiveX equivalents to those we know as GETxxx functions in AutoLISP. Notice the first argument in VLA-GET-UTILITY. It means that the Utility object is a child of the application.

The whole thing could schematically look like this:
Code: [Select]

AutoCAD application  -->  Utilities object (to get points etc.)
        |                       |
        v                  vla-getPoint pt1
  Active document          vla-getPoint pt2
        |                       |
        v                       v
   Modelspace        -->   vla-addLine Modelspace pt1 pt2
                                |
                                v
                           Line object

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
(challenge) newbie Create a line function .......
« Reply #20 on: October 15, 2004, 11:08:05 AM »
Nice explanation Mr. Madsen.

Major code overkill, but maybe it will help.
Code: [Select]

(defun c:aline (/ get-utilobj get-mspace vl-get-point acitvexline pt1 pt2 ax_line)
  (vl-load-com)

  ;;; this program will draw a line between the two user selected points
  ;;; it uses all activeX methods including the point selection.

  ;----------------------------------------------------------------------
  ; *internal function*
  ;
  ; returns the utility object (VLA-OBJECT IAcadUtility)
  ; for the active document
  ;----------------------------------------------------------------------
  (defun get-utilobj ()
    (vla-get-utility
      (vla-get-activedocument
        (vlax-get-acad-object)
        )
      )
    )

  ;----------------------------------------------------------------------
  ; *internal function*
  ;
  ; returns the modelspace object (VLA-OBJECT IAcadModelSpace2)
  ; for the active document
  ;----------------------------------------------------------------------
  (defun get-mspace ()
    (vla-get-modelspace
      (vla-get-activedocument
        (vlax-get-acad-object)
        )
      )
    )

  ;----------------------------------------------------------------------
  ; *internal function*
  ;
  ; a getpoint function that uses the Utility object of the active document
  ;
  ; returns a variant (three-element array of doubles) #<variant 8197 ..>
  ; of the user selected point or NIL.
  ;
  ; (vl-get-point variant_array_of_dbls,[nil] "message for user prompt")
  ;----------------------------------------------------------------------
  (defun vl-get-point (pt msg / pt_variant)

    (setq pt_variant
          (vl-catch-all-apply
            'vlax-invoke-method
            (list
              (get-utilobj)
              'GetPoint
              pt
              (vlax-make-variant msg)
              )
            )
          ); setq

    (if (vl-catch-all-error-p pt_variant)
      nil pt_variant
      ); if
    )

  ;----------------------------------------------------------------------
  ; *internal function*
  ;
  ; creates and returns a line object (VLA-OBJECT IAcadLine)
  ;
  ; (acitvexline variant_array_of_dbls variant_array_of_dbls)
  ;----------------------------------------------------------------------
  (defun acitvexline (startpt endpt)
    (vla-addline (get-mspace) startPt endPt)
    )

  ;; ========== body of main function (aline) starts here ===========

  ;; loop while we're getting valid input.
  (while (setq pt1 (vl-get-point nil "\nStart Point: "))

         (if (setq pt2 (vl-get-point pt1 "\nEnd Point: "))
           (progn
             (setq ax_line (acitvexline pt1 pt2))
             (vlax-release-object ax_line)
             )
           )

         ); while

  (princ)

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

Oak3s

  • Guest
Re: (challenge) newbie Create a line function .......
« Reply #21 on: July 26, 2006, 06:13:51 PM »
very old challenge but i was busy trying to figure it out anyway. so here is what i have. striped down, no error handling stab at it.
Code: [Select]
(defun c:YL (/)
(setq pt1 (getpoint "Starting point : ")
          pt2 (getpoint "Ending point : "))
(entmake (list '(0 . "line") '(62 . 2) (cons 10 pt1) (cons 11 pt2)))
)

the quote ' was what was messing me up. i still dont really get why its working with the ' before the dxf code and not my variables...but it works. any suggestions or comments welcome.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: (challenge) newbie Create a line function .......
« Reply #22 on: July 26, 2006, 06:18:10 PM »
very old challenge but i was busy trying to figure it out anyway. so here is what i have. striped down, no error handling stab at it.
Code: [Select]
(defun c:YL (/)
(setq pt1 (getpoint "Starting point : ")
          pt2 (getpoint "Ending point : "))
(entmake (list '(0 . "line") '(62 . 2) (cons 10 pt1) (cons 11 pt2)))
)

the quote ' was what was messing me up. i still dont really get why its working with the ' before the dxf code and not my variables...but it works. any suggestions or comments welcome.
The quote means take things literial, so
'(0 . "line") = (0 . "line")
'(cons 10 pt1) = (cons 10 pt1)

And since you have variables in the dxf code, you have to use (list... instead of '(...... with your entmake.  This is because you have to evaluate the variables [pt1 pt2].

Hope that makes it clearer.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Bob Wahr

  • Guest
Re: (challenge) newbie Create a line function .......
« Reply #23 on: July 26, 2006, 06:20:51 PM »
Nice 3Oaks ;)

Joe Burke

  • Guest
Re: (challenge) newbie Create a line function .......
« Reply #24 on: July 27, 2006, 06:45:01 AM »
One more thing which is on my mind since I forgot to do it in some
code I posted yesterday.

If the points are derived from getpoint, trans those to WCS for correct
operation in a UCS. Both entmake and vla-Add methods require WCS points.

(setq p1 (trans (getpoint "\nFirst point: ") 1 0))