Author Topic: Pseudo Code  (Read 1960 times)

0 Members and 1 Guest are viewing this topic.

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Pseudo Code
« on: March 23, 2005, 08:59:46 AM »
The topic of Pseudo Code just arose and i wanted to share with you some of my "syntax" for Pseudo code.

I wanted to give an example too so im gonna include a small project i was working on. (Well i started it and didnt get a chance to look at it since, but you get my point.) Take a look at the header and you'll get an idea about how i go about starting a code project. (I try to do this for all my projects but im not perfect.)

Pardon the spelling mistakes. (Spelling is not a priority when i do this.)

Code: [Select]
;;;===================================================================;
;;;              C H A N G E   L A Y E R   C O L O R                  ;
;;;-------------------------------------------------------------------;
;;; Project:        Change layer color of selected item.              ;
;;; Date:           03.15.05                                          ;
;;; Author:         John (Se7en) K.                                   ;
;;; Notes:          This is for a guy in my office. He "sets up" the  ;
;;;                 drawings in the office. This was a request.       ;
;;;-------------------------------------------------------------------;
;;; Symbol Key:                                                       ;
;;; *    =     Subject.                                               ;
;;; -    =     Topic.                                                 ;
;;; ~    =     Note or thing(s) to be aware of. (Conditional)         ;
;;; [    =     Begin loop                                             ;
;;; ]    =     End loop                                               ;
;;; }    =     A reference or an example to help defign my thoughts.  ;
;;;                                                                   ;
;;; Pseudo code:                                                      ;
;;;                                                                   ;
;;; ** User interaction. **                                           ;
;;; - Get selected item from user.                                    ;
;;;    ~ Support for preselected items would be cool.                 ;
;;;                                                                   ;
;;; ** Test the environment. **                                        ;
;;; - Test to see if the item is a block or xref.                     ;
;;; - Retrieve the layer property from item.                          ;
;;;    ~ If it is a block or xref, get the top level layer prop.      ;
;;; - Retrieve the layer property from the Drawing data base.         ;
;;; - Test to see if the layer is locked.                             ;
;;;    ~ If the layer is locked, prompt the user and quit.            ;
;;;                                                                   ;
;;; ** User interaction. **                                           ;
;;; - Retrieve the proposed color for the layer.                      ;
;;;                                                                   ;
;;; ** Make proposed changes **                                       ;
;;; - change the layer color.                                         ;
;;; - update the drawing. (refresh)                                   ;
;;;                                                                   ;
;;; ** Clean up **                                                    ;
;;; - Done.                                                           ;
;;;===================================================================;

;;;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
;;;   Begin code development.                                         ;
;;;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;

;;; ** User interaction. **                                           ;
;;; - Get selected item from user.                                    ;
;;;    ~ Support for preselected items would be cool.                 ;

;;;===================================================================;
;;; Selected-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))))

;;;===================================================================;
;;; Get-Selcted                                                       ;
;;;-------------------------------------------------------------------;
;;; 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-Selcted))                     ;
;;;                                                                   ;
;;;-------------------------------------------------------------------;
;;; Version: 1.1 Added the ability to have more then one selected     ;
;;;              objects on the screen.                               ;
;;;===================================================================;
(defun Get-Selcted (/ 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))))))
    ((= xlength nil)
     (while (not (setq x (entsel "\nselect object: "))))
     (setq x (car x))
     (sssetfirst nil)
     (redraw x 3)))
  (if (= nil xlist) x xlist)
)

;;; ** Test the enviroment. **                                        ;
;;; - Test to see if the item is a block or xref.                     ;

;;;===================================================================;
;;; block-p                                                           ;
;;;-------------------------------------------------------------------;
;;; test to see of given is a block                                   ;
;;; Returns: Boole                                                    ;
;;; Author: John (Se7en) Kaul                                         ;
;;; Date: 03.15.05                                                    ;
;;;===================================================================;
;;;(defun block-p (x)
;;;  (and (caddr (nentselp (cadr x)))))
;;;
;;; //-- Status: On hold till validity is verified. --//
;;;

;;; - Retrieve the layer property from item.                          ;
;;;    ~ If it is a block or xref, get the top level layer prop.      ;

;;;===================================================================;
;;; Get layer                                                         ;
;;;-------------------------------------------------------------------;
;;; Get the layer of the entity.                                      ;
;;; Returns: String                                                   ;
;;; Example: (getlayer (entsel))                                      ;
;;;       > "0"                                                       ;
;;; Author: John (Se7en) Kaul                                         ;
;;; Date: 03.15.05                                                    ;
;;;===================================================================;
(defun getlayer (x)
  (cdr (assoc 8 (entget x))))

;;;*******************************************************************;
;;; Test 1                                                            ;
;;;-------------------------------------------------------------------;
;;; This is test number one. I am testing to see if I can retrieve    ;
;;; an entities layer if it is selected on the screen before my code  ;
;;; runs.                                                             ;
;;;*******************************************************************;
(defun test1 ()
  (getlayer (Get-Selcted)))
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

nivuahc

  • Guest
Pseudo Code
« Reply #1 on: March 23, 2005, 11:32:40 AM »
That's a very good idea John. If you use your psuedo code and build your routine on top of it, it ought to make documenting your code (something that I preach heavily, but suck at myself) that much simpler!

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Pseudo Code
« Reply #2 on: March 23, 2005, 03:23:02 PM »
Thats one benefit i see to it. But the overall, whole idea is to develop the logic behind the code first then work on the code itself. (Makes developing and debuging code a whole mess easier!)
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org