Author Topic: Copy Rotate -Feedback  (Read 6306 times)

0 Members and 1 Guest are viewing this topic.

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
Copy Rotate -Feedback
« on: November 10, 2003, 02:11:23 PM »
Can i get some feedback form you guys? I wanted a little tool i can pass on to presptive employers and this is what i came up with.

I coded some of the major stuff in here (But its still not done) but i wanted feed back on the process, code, etc.. (all that good stuff) Let me know if it dosent work or you see a potential bug.

7

Code: [Select]
;;;===================================================================;
;;; UNDO GORUPING FUNCTIONS                                           ;
;;;===================================================================;
(defun vl-UndoBegin ()
  (vla-StartUndoMark
    (vla-get-activedocument (vlax-get-acad-object))))
(defun vl-UndoEnd ()
  (vla-EndUndoMark
    (vla-get-activedocument (vlax-get-acad-object))))

;;;===================================================================;
;;; Get-EntSelcted                                                    ;
;;;-------------------------------------------------------------------;
;;; This function will offer a way for the programer to get an        ;
;;; entity or entities already slected on the screen before the       ;
;;; program took control. This program was intended for use in an     ;
;;; ActiveX program. I have chosen not to use the "Pickfirst" method  ;
;;; in accomplishing this task because I wanted a way to do this even ;
;;; if the "pickfirst" variable was toggled to zero. If no entity is  ;
;;; currently selected on the screen, this function will prompt the   ;
;;; end user to select an entity.                                     ;
;;;                                                                   ;
;;; Author: John Kaul                                                 ;
;;;                                                                   ;
;;; Returns: Either previously selected entity, a selected entity, or ;
;;;          a list of selected entities.                             ;
;;;                                                                   ;
;;; Usage: (vlax-ename->vla-object (Get-EntSelcted))                  ;
;;;                                                                   ;
;;;-------------------------------------------------------------------;
;;; Version: 1.1 Added the ability to have more then one selected     ;
;;;              objects on the screen.                               ;
;;;===================================================================;
(defun Get-EntSelcted (/ x cntr xlength xlist)
  (setq x (cadr (ssgetfirst)))
  (if x (setq xlength (sslength x)))
  (cond
    ((= xlength 1)
     (setq x (ssname x 0))
     (sssetfirst nil)
     (redraw x 3))
    ((> xlength 1)
     (setq cntr xlength)
     (cond
       ((>= cntr 2)
        (setq cntr (1- xlength))
        (while (>= cntr 0)
               (setq xlist (cons (ssname x cntr) xlist)
                     cntr  (1- cntr)))
        (foreach a xlist (progn (sssetfirst nil) (redraw a 3))))))
    )
  (if (= nil xlist) x xlist)
)
;;;===================================================================;
;;; Slected-p                                                         ;
;;;-------------------------------------------------------------------;
;;; This function will test to see if something is selected on screen ;
;;;                                                                   ;
;;; Returns: T or nil                                                 ;
;;;                                                                   ;
;;; Author: John Kaul                                                 ;
;;;                                                                   ;
;;; Usage: (if (not (Slected-p))                                      ;
;;;          (vlax-ename->vla-object (car (entsel))))                 ;
;;;===================================================================;
(defun Slected-p ()
  (and (cadr (ssgetfirst)))
 )
;;; FUNCTION
;;; catchs any errors in selection process
;;; returns a valid VLA-OBJECT or nil
;;; *requires* 'Selected-p' by John Kaul
;;;
;;; ARGUMENTS
;;; none
;;;
;;; USAGE
;;; (setq obj (MST-Select-It))
;;;
;;; PLATFORMS
;;; 2000+
;;;
;;; AUTHOR
;;; Copyright© 2003 Mark S. Thomas
;;; mark.thomas@theswamp.org
;;;
;;; VERSION
;;; 1.0 Tue Sep 16, 2003 07:04:21
;;; 1.1 Mon Nov, 10 2003 ~I chaged the "if" expression to
;;;                       a "cond" and added a highlight
;;;                       feature. John Kaul
(defun MST-Select-It (/ obj)
  (if
    (vl-catch-all-error-p
      (cond
        ((not (Slected-p))
         (setq obj
               (vl-catch-all-apply
                 'vlax-ename->vla-object
                 (list (setq ent (car (entsel))))
                 )
               )
         (redraw ent 3)
         )
        )
      )
    (setq obj nil)
    )
  obj
  )
;;;*******************************************************************;
;;; copy rotate                                                       ;
;;;-------------------------------------------------------------------;
;;; This function will eventualy be a new command in autocad. It will ;
;;; over the user to copy rotate an object.                           ;
;;;                                                                   ;
;;; TODO: Rotate the object.                                          ;
;;;       Error trap                                                  ;
;;;*******************************************************************;
(princ "\nType \"CR\" to run. ")
(defun c:cr ( )
  (vl-UndoBegin)
  (cond
    ((not (Slected-p))
     (setq obj (MST-Select-It)))
    ((Slected-p)
     (setq obj (vlax-ename->vla-object (Get-EntSelcted))))
    )
  (vla-Copy obj)
  (vla-Move obj
            (vlax-3d-point
              (setq pt (getpoint
                         "\nSpecify first point:")))
            (vlax-3d-point
              (setq pt2 (getpoint pt
                                  "Specify second point:")))
            )
  ;;;  (vla-Rotate obj pt2)  
  (vl-UndoEnd)
 )
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Ron Heigh

  • Guest
Copy Rotate -Feedback
« Reply #1 on: November 10, 2003, 03:37:19 PM »
Code: [Select]
UNDO GORUPING FUNCTIONS
What does this mean?

Columbia

  • Guest
Copy Rotate -Feedback
« Reply #2 on: November 10, 2003, 04:14:41 PM »
I don't know how far you are already in this, but here are just a few tips that may (or may not) save you a few headaches down the road...

1.) in the vl-UndoBegin sub-function I recommend that you add a vla-EndUndoMark call to close any marks or groups that have been left hangin' around and open like this:
Code: [Select]

(defun vl-UndoBegin ()
  (vla-EndUndoMark (vla-get-ActiveDocument (vlax-get-acad-object)))
  (vla-StartUndoMark (vla-get-activedocument (vlax-get-acad-object)))
)


2.) that you add a custom Error Handler function to set the EndUndoMark at unexpected function interruption (i.e. the user hits 'Escape' about 100 x's.)
Code: [Select]

(defun *error* (s)
  (if
    ( (not
      (member (strcase s t)
        '("quit / exit abort" "function cancelled" "console break")
      )
    )
    (progn (princ (strcat "\nError: " s)) (vl-bt))
  )
  (vla-EndUndoMark (vla-get-ActiveDocument (vlax-get-acad-object)))
)

What you would want to do at this point is to make sure that this error handler function is a localized defun inside the main routine.  That way it doesn't clobber the pre-set AutoCAD one.

3.) you might want to consider putting your selection calls in a (while) loop to ensure that you get something, or if you don't that you don't cause the program to fail.

Any questions about what I'm talking about, then please ask...otherwise Good Luck!

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
Copy Rotate -Feedback
« Reply #3 on: November 10, 2003, 05:52:06 PM »
That "close any undo's" is  a good idea.  Im goona use that one.

Error trap was on the list of TODO.

while loop is also a good idea. (I was thinking the same thing. ...I got one i use for alot of apps that didnt get in here yet.)

Thanks for the reply

OBTW, Did you ever get your XML problems solved? (I dont know if you emailed me or not, but i dont have that email addy i gave you anymore. So...)
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Columbia

  • Guest
Copy Rotate -Feedback
« Reply #4 on: November 10, 2003, 06:47:22 PM »
Yeah, I found the answer I was looking for.  Curiously enough on the Microsoft MSDN website.  Go figure, I guess you can acutally find useful information on there.  :-)

Anyway, I hoped I helped a little.  If you have any other questions/comments/concerns or random shots of profanity, well then I'm all ears.

daron

  • Guest
Copy Rotate -Feedback
« Reply #5 on: November 10, 2003, 08:18:17 PM »
Quote
2.) that you add a custom Error Handler function to set the EndUndoMark at unexpected function interruption (i.e. the user hits 'Escape' about 100 x's.)

It's been a while since I tried to hit escape 100 x's, but if I recall correctly, I was able to crash the *error* handler. Just a thought.

Columbia

  • Guest
Copy Rotate -Feedback
« Reply #6 on: November 10, 2003, 10:22:12 PM »
That's true.  If the user has had too much coffee, he/she could crash the error handler if the escape key is pushed fast enough.  The only way that I have found around that is to use recursion.  But that method gets really chunky, tricky, quirky and memory intensive really quickly.

So my method is to tell the user if they didn't have happy  fingers then they wouldn't have as many problems.  And overall I subscribe to the theory that it's better to have some kind of error handling function, then let it be a free-for-all.

daron

  • Guest
Copy Rotate -Feedback
« Reply #7 on: November 11, 2003, 12:18:16 AM »
I've only done it once and it was on purpose. To see if it could be done. Although, I've seen co-workers mutilate the escape key at the speed of light. Kinda scary. But, I do agree with you.