Need help tying together Two LISP routines

Need help tying together Two LISP routines

zdavisMLD73
Explorer Explorer
823 Views
4 Replies
Message 1 of 5

Need help tying together Two LISP routines

zdavisMLD73
Explorer
Explorer

Good evening,

I'm in the process of building a routine that will allow a user to quickly draw a roof layout. Most of the code has been adapted from other LISP routines found around the web, so I know there are probably redundancies and issues with the code. The main routine, ROLLG, is meant to do the bulk of the routine.  AutoCAD 2020, windows 10.

 

To test the functionality, these parameters would work:

Enter type of material: DL

Enhanced perimeter?: 5

Building Height?: 50

Parapet Height?: 50

 

After entering those parameters, and selecting the left and right sides of a rectangle (exploded), the user can offset a series of lines towards the inside of the rectangle, so that there is a series of adjacent parallel lines. After that, I am trying to tie together another LISP routine (RollG-Array) that allows a user to have an array of parallel lines populate in the center of the rectangle (every 60 inches)

 

When I try to insert the Rollg-Array code at the end of the Rollg code, it doesn't want to run the code in the Rollg-Array... I'm guessing there are errors with the main piece of code. Is there anybody that could help me out with this issue?

 

Thanks!

 

Here is the RollG code:

(defun c:EWC (/) (c:RollG)) 
(defun c:RollG (/ *error* AT:Offset #SS #Pnt #Temp #Inc
			 *OO:Del* *OO:Cur* *OO:Num*
		)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; SUBROUTINES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;; error handler
  (defun *error* (#Message)
    (and *AcadDoc* (vla-endundomark *AcadDoc*))
    (and #Message
         (not (wcmatch (strcase #Message) "*BREAK*,*CANCEL*,*QUIT*"))
         (princ (strcat "\nError: " #Message))
    ) ;_ and
  ) ;_ defun



;;; Offset selected object
;;; O - Object to offset
;;; D - Distance to offset object
;;; P - Point on side of object to offset
  (defun AT:Offset (O D P / _pt p1 p2 c D g)
    (setq
      _pt (lambda (s) (vlax-curve-getPointAtDist O (s (vlax-curve-getDistAtPoint O p1) 0.00001)))
    ) ;_ setq
    (if (and (setq p1 (vlax-curve-getclosestpointtoprojection O (trans P 1 0) '(0 0 1)))
             (or (setq p2 (setq c (_pt +))) (setq p2 (_pt -)))
             (if (minusp (- (* (- (car p2) (car p1)) (- (cadr (trans P 1 0)) (cadr p1)))
                            (* (- (cadr p2) (cadr p1)) (- (car (trans P 1 0)) (car p1)))
                         ) ;_ -
                 ) ;_ minusp
               (if (vl-position (vla-get-objectname O) '("AcDbLine" "AcDbXline"))
                 (setq D (- (abs D)))
                 (setq D (abs D))
               ) ;_ if
               (if (vl-position (vla-get-objectname O) '("AcDbLine" "AcDbXline"))
                 (setq D (abs D))
                 (setq D (- (abs D)))
               ) ;_ if
             ) ;_ if
             (or c (setq D (- D)))
             (not (vl-catch-all-error-p (setq g (vl-catch-all-apply 'vla-offset (list O D)))))
        ) ;_ and
      (car (vlax-safearray->list (vlax-variant-value g)))
    ) ;_ if
  ) ;_ defun
  
  
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; MAIN ROUTINE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Get User Inputs	



(initget "DL DT")
(if (setq MAT (getkword "\nEnter type of material [DL/DT]: "))
   (if (= MAT "DT")
	(progn
	 (initget "5 10")
	 (setq ROLLSIZE (getint "\nEnter Roll Size [5/10]: "))
	)
	(progn
	 (setq ROLLSIZE 5)
	)
   );end if
);end if

(setq EP (getreal "\nEnhanced Perimeter? (Ft) : "))
;get the enhanced perimeter based off of the windcalc dimension

(setq BH (getint "\nBuilding Height? (Ft) : "))
;get the building height

(setq PP (getint "\nParapet Height? (inches) : "))
;get the parapet height

  
;****************************************************************
  ;command process
  ;; Global variables
  (or *OO:Dist* (setq *OO:Dist* 1.))
  (or *OO:Del* (setq *OO:Del* "No")) ;local
  (or *OO:Cur* (setq *OO:Cur* "Yes")) ;local
  (or *OO:Num* (setq *OO:Num* 1)) ;local
  (or *OO:Side* (setq *OO:Side* "Single"))

  (or *AcadDoc* (setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object))))

  (vla-startundomark *AcadDoc*)



(cond ((and (>= BH 40) (< BH 80)
  (cond
    ((and

       (setq #SS (ssget "_:L" '((0 . "ARC,CIRCLE,ELLIPSE,LINE,LWPOLYLINE,SPLINE,XLINE"))))
       (cond ((eq *OO:Side* "Single") (setq #Pnt (getpoint "\nSpecify point on side to offset: ")))
             ((eq *OO:Side* "Both") T)
       ) ;_ cond
     ) ;_ and
     (vlax-for x (setq #SS (vla-get-activeselectionset *AcadDoc*))
       (setq #Inc 0.)
         (setq #Inc (1+ #Inc))
         (cond
           ((eq *OO:Side* "Single")
            (and (setq #Temp (AT:Offset x (* #Inc 26) #Pnt))
		 (AT:Offset x (* #Inc 52) #Pnt))
	    	 (AT:Offset x (* #Inc (* EP 12)) #Pnt)));ENHANCED PERIMETER (CONVERTED TO FEET)
	 	 (command "chprop" (entlast) "" "c" "1" "lt" "Continuous" "")
            ) ;_ and
           )
         ) ;_ cond
     ) ;_ vlax-for
  ) ;_ cond
 (prompt "\nSelect the RIGHT side of the field: ")
 (setq ss1 (ssget))
 (setq a_path (car (entsel "\nSelect array path: ")))

      
 );_cond

) ;_ defun

 

 

Here is the RollG-Array code:

(defun c:ap10 ( / ss1 a_path)
(setvar "cmdecho" 0)
(prompt "\nSelect wall on RIGHT side: ")
(setq ss1 (ssget))
(setq a_path (car (entsel "\nSelect array path: ")))
(if (and ss1 a_path)
(command "_arraypath" ss1 "" a_path "" "" "" "_F" "60" "" "")
(princ "\nNo array created!")
)
(princ)
)

 

0 Likes
Accepted solutions (1)
824 Views
4 Replies
Replies (4)
Message 2 of 5

Moshe-A
Mentor
Mentor
Accepted solution

@zdavisMLD73  hi,

 

Attached ROLLG.LSP fixed but not tested.

 

on the other hand i think it's better to leave the two lisps separately cause there is always a possibility of errors in ROLLG and at this case you will always want to cancel it all.

 

enjoy

moshe

 

 

0 Likes
Message 3 of 5

zdavisMLD73
Explorer
Explorer

Hi Moshe,

 

Thanks for the helpful response. I was hoping to piece them together in one file so I wouldn't have to load both, but actually that works fine. I modified the rollg-array LISP so that the user can draw a line and then use that line to select during the drawing of the array, but the code breaks before I can get that far. any idea what I'm doing wrong here?

(defun c:ap10 ( / ss1 a_path pnt1 pnt2)
(setvar "cmdecho" 0)
(setq pnt1 (getpoint "\nSelect bottom left corner of field area: "))
(setq pnt2 (getpoint "\nSelect bottom right corner of field area: "))
(command "line" pnt1 pnt2 "")
(prompt "\nSelect wall on RIGHT side: ")
(setq ss1 (ssget))
(setq a_path (car (entsel "\nSelect array path: ")))
(if (and ss1 a_path)
(command "_arraypath" ss1 "" a_path "" "" "" "_F" "60" "" "")
(princ "\nNo array created!")
)
(princ)
)
0 Likes
Message 4 of 5

zdavisMLD73
Explorer
Explorer

Okay, so it seems to be working now (not sure why it was giving me problems earlier) - however, it likes to array to the right of my selection (sometimes). other times, it likes to array to the left.... any way to control the direction?

 

Ideally, I would like to select the left wall and have it array to the right every time. But really a consistent array path is all that matters.

 

Thank you!!

0 Likes
Message 5 of 5

Sea-Haven
Mentor
Mentor

There was a post about creating roofs, the solution was based on any shape pline, I think it was done by Maratovich. search cadtutor as well. This is an old question and solutions are like 30 years old. I do it via 1st principals in 3d Gable, Valleys, ridges etc.

0 Likes