samifox Posted July 26, 2013 Share Posted July 26, 2013 Hi Recently I experience weird things with the de******. It skips expressions with no reason. I tried as a single file and as project, both the same. Here is the code, I notice the de****** skips the :addColumn() Could anyone please run and test it? (vl-load-com) (setq mspace (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object) ) ) ) (setq NORTH (/ pi 2) WEST pi SOUTH (* 3 (/ pi 2)) EAST0 0 EAST (* pi 2) ) (setq MAXDISTANCE 58) ;_maximum distance for root squre defenition (setq MINDISTANCE 26) ;_minimum distance for root squre defenition (setq COLUMN_DATABASE nil) (setvar 'pdmode 34) (setvar 'cmdecho 0) (setq debug 1) ;;;********************************************************************; ;;; Function: C:MMD The Main MMD Function ; ;;;--------------------------------------------------------------------; ;;; Description: This is the main function of the MMD application and . ;;; handles all calling and reciving data from the classes ;;;********************************************************************; (defun C:MAIN (/ sspl pts corners walls) (setvar "OSMODE" 0) (if (setq sspl (ssget '((0 . "LWPOLYLINE")))) ;_ask the user to window select (progn (setq corner (MMDPOLY1:createCornerVertexList (MMDPOLY1:createLinearVertexList sspl)));_create corner vertices list (setq i 0) (while (< i (/ (length corner)2 )) (setq COLUMN_DATABASE;_store column definition in database (cons (MMDCOLUMN:createColumnDefention (nth i corner) (nth (+ i 1) corner) i) COLUMN_DATABASE ));_send every 2 vertices (setq[color="red"] addColumn[/color](MMDCOLUMN:getColumnCoordinates i ));_draw column (setq i (1+ i)) );_while );_progn );_if );_defun ;;;******************************************************************;;; ;;; CLASS : MMDPOLY ; ;;;--------------------------------------------------------------------; ;;; Description: This class manipulate,analyze and compute vertices ; ;;; lists of a given selection set or vertices list ; ;;;******************************************************************;;; ;;;--------------------------------------------------------------------; ;;; Function: createLinearVertexList ; ;;;--------------------------------------------------------------------; ;;; Description: create a 3d vertices list based of the a given ; ;;; selection set. ; ;;; Argument : sspl - Selection Set ; ;;;--------------------------------------------------------------------; (defun MMDPOLY1:createLinearVertexList ( sspl / i pts tpts) (progn (setq i 0) (while (< i (sslength sspl)) (setq pts (mapcar 'cdr(vl-remove-if-not'(lambda (e) (= (Car e) 10))(entget (ssname sspl i))))) (setq i (1+ i)) (setq tpts (cons pts tpts)) ) ) (apply 'append tpts) ) ;;;--------------------------------------------------------------------; ;;; Function: createCornerVertexList ; ;;;--------------------------------------------------------------------; ;;; Description: analyzes a given 2d vertices list by comparing every ; ;;; pair of vertices for all possible distances and ; ;;; angles, and create a new list of 2d vertices only ; ;;; they form 90 degrees corner. ; ;;; Argument : lst - 2d vertices list ; ;;;--------------------------------------------------------------------; ;;; anglein radianc but for comprance ; ;;; porpuses,there is a need for the ; ;;; (<) and (>)functionsthe get 0 or ; ;;; (* pi 2) as arguments ; ;;; MAXDISTANCE - the maximum distance allowed between 2 ; ;;; pointsto be listed as a corner pair ; ;;; vertices. ; ;;; MINDISTANCE - the minimum distance allowed between 2 ; ;;; vertecis to be listed as a corner ; ;;; vertices. ; ;;; notice that this constant prevent ; ;;; vertex to be compared to it self and ; ;;; other verticesin a door or a window ; ;;; posts. ; (defun MMDPOLY1:createCornerVertexList(lst / ma fe col corners ) (setq fe 0 ma 0) (while (< ma (length lst)) (while (< fe (length lst)) (if(MMDPOLY.isCornerForm (nth ma lst)(nth fe lst) MINDISTANCE MAXDISTANCE) (if (not (or (member (nth ma lst) corners) (member (nth fe lst) corners) (not(equal corners nil)))) (progn (setq corners (cons (nth ma lst)corners)) (setq corners (cons (nth fe lst)corners)) ) ) ) (setq fe (1+ fe)) );_while (fe (setq ma (1+ ma))(setq fe 0) ) ;_while (ma corners ) ;;;------------------------------------------------------------------------; ;;; Function: MMDPOLY.isCornerForm (Helper of createCornerVertexList) ; ;;;------------------------------------------------------------------------; ;;; Description: compares a given pair of points for having the ; ;;; specific pose of an orthographic corner which are, ;;; an angle and distance between pair of vertices. ;;; ;;; Argument : p1 p2 - 2d or 3d vertices to be compared ;;; : mn mx - distance range ;;; Return : t - if the compared vertices form a corner ;;; nil - if the compared vertices dont form a corner ;;; Constant : NORTH - a radian equalent to (/ pi 2) ; ;;; WEST - a radian equalent to pi ; ;;; SOUTH - (* 3 (/ pi 2)) ; ;;; EAST0/EAST - 0 and (* pi 2) representing the same ; ;;;--------------------------------------------------------------------; (defun MMDPOLY.isCornerForm(p1 p2 mn mx) (cond ((and (< (angle p1 p2) NORTH) (> (angle p1 p2) EAST0) (< (fix (distance p1 p2)) mx)(> (fix (distance p1 p2)) mn)) t) ((and (> (angle p1 p2) NORTH) (< (angle p1 p2) WEST ) (< (fix (distance p1 p2)) mx)(> (fix (distance p1 p2)) mn)) t) ((and (> (angle p1 p2) SOUTH) (< (angle p1 p2) EAST ) (< (fix (distance p1 p2)) mx)(> (fix (distance p1 p2)) mn)) t) ((and (< (angle p1 p2) SOUTH) (> (angle p1 p2) WEST ) (< (fix (distance p1 p2)) mx)(> (fix (distance p1 p2)) mn)) t) (t nil);_angle is ortho );_cond );_defun ;;---------------------------------------------------------------------------------; ;;; Function: MMDPOLY.orthoValidation ; ;;;---------------------------------------------------------------------------------; ;;; Description: check the members of the given selection set for ; ;;; the following requirments: ; ;;; 1.entity must be polyline ; ;;; 2.must be closed polyline ; ;;; 3.must be orthographic (within the boundry of the givn tolorance ; ;;; Pasadu : ; ;;; * if sset has a polyline defenition ; ;;; * if sset has closed defenition on ; ;;; *if sset poly geometry is ortographic (tolotance) ; ;;; * return T ; ;;; * print : one or more polyline are not orthographic ; ;;; * print : one or more polyline are not orthographic ; ;;; * print : one or more entites in the selection set ; ;;; is not polylines ; ;;;---------------------------------------------------------------------------------; ;;; Argument : sset - a selection set ; ;;; Return : tol - the tolorance allowed for a line to be consider orthogaphic.; ;;;---------------------------------------------------------------------------------; (defun addColumn (ptlist / pt tmp myobj a) ;convert 3d to 2d (setq ptlist(mapcar '(lambda (p) (list (car p) (cadr p)))ptlist)) ;; "dissolve" the points into atoms with append: (setq ptlist (apply 'append ptlist)) ;; If number of coordinates in point list is not ;; a multiple of 2 then a polyline can't be made. ;; If it's a multiple of 2 then put the point ;; list into an array and pass it on to vla-AddLightWeightPolyline (if (= (rem (length ptlist) 2) 0) (progn (setq tmp (vlax-make-safearray vlax-vbDouble (cons 0 (- (length ptlist) 1)) ) ) (vlax-safearray-fill tmp ptlist) (setq myobj (vla-AddLightWeightPolyline mspace tmp)) ) (princ "\nerror: Polyline could not be created") ) ) ;;;******************************************************************;;; ;;; CLASS : COLUMN ; ;;;--------------------------------------------------------------------; ;;; Description: This class creates a column definition list by a ; ;;; given pair of vertices and provides function to ; ;;; read the column definition. ; ;;;******************************************************************;;; ;;;--------------------------------------------------------------------; ;;; Function: MMDCOLUMN.createColumnDefention ; ;;;--------------------------------------------------------------------; ;;; Description: Creates a column definition ; ;;; Argument : p1,p2 - pair of 2d vertices ; ;;; id - column id ; ;;;--------------------------------------------------------------------; ;;; Association List ; ;;; 0 - ID number ; ;;; 10 - 4 coordinates ; ;;; 11 - center point ; ;;; 40 - Width ; ;;; 41 - Hight ; ;;; 50 - Base angle, that is the angle of the ; ;;; original pair of points that were used to ; ;;; create the culomn definition.create ; (defun MMDCOLUMN:createColumnDefention(p1 p3 id) (cons (setq lst (list (cons 0 id) (cons 10 (list p1 p3 (list (car p3) (cadr p1)) (list (car p1) (cadr p3)))) (cons 11 (list (setq mid (mapcar '(lambda (x y) (* 0.5 )) p1 p3)))) (cons 40 (abs (- (car p1) (car p3)))) (cons 41 (abs (- (cadr p1) (cadr p3)))) (cons 50 (angle p1 p3))) );_list lst );_cons lst );_defun (defun MMDCOLUM:getColumnID(c) (cdr(assoc 0 (nth c COLUMN_DATABASE))) ) (defun MMDCOLUMN:getColumnCoordinates(c) (cdr(assoc 10 (nth c COLUMN_DATABASE))) ) (defun MMDCOLUMN:getColumnCenter(c) (cdr(assoc 11 (nth c COLUMN_DATABASE))) ) (defun MMDCOLUMN:getColumnHight(c) (cdr(assoc 40 (nth c COLUMN_DATABASE))) ) (defun MMDCOLUMN:getColumnWidth(c) (cdr(assoc 41 (nth c COLUMN_DATABASE))) ) (defun MMDCOLUMN:getColumnBaseAngle(c) (cdr(assoc 50 (nth c COLUMN_DATABASE))) ) Quote Link to comment Share on other sites More sharing options...
neophoible Posted July 26, 2013 Share Posted July 26, 2013 Why are you doing this (setq addColumn(MMDCOLUMN:getColumnCoordinates i ) Isn't that one of your functions you are overwriting? Quote Link to comment Share on other sites More sharing options...
samifox Posted July 27, 2013 Author Share Posted July 27, 2013 you right! thanks Quote Link to comment Share on other sites More sharing options...
neophoible Posted July 28, 2013 Share Posted July 28, 2013 you right!thanks You're quite welcome of course. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.