Muthanna Posted December 1, 2014 Posted December 1, 2014 (edited) Hi everyone, I am a software developer , i program in C# C++ and Java, but lately i have been given a task to help out our engineering department to write some code + script to fix cad prints which they have issues with. our problem is we use a third party application which generates an AutoCad drawing. this third part application sets the dimscale to 1:000; But the drawing's title block scale attribute has has the correct scale value. My task was to write code in lisp and our script to automate this process; which will requires the program to read the value for the scale attribute and apply it to the drawing dimscale. after reading some tutorials and searching the web i cam across some functions that did most of my task...Thanks to this community and its forums. my main function that reads the attribute value i got from on of the threads as shown below: (defun c:AttLst (/ ss eLst bEnt aEnt aEntLst aVal blkLst) (vl-load-com) (if (setq ss (ssget "X" (list (cons 0 "INSERT") (cons 66 1) (if (getvar "CTAB") (cons 410 (getvar "CTAB")) (cons 67 (- 1 (getvar "TILEMODE"))))))) (progn (setq eLst (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))) (foreach e eLst (setq bEnt (cdr (assoc 2 (entget e))) aEnt (entnext e)) (while (= "ATTRIB" (cdr (assoc 0 (setq aEntLst (entget aEnt))))) (if (= (cdr (assoc 2 aEntLst)) "SCALE") (progn (setq aVal (cdr (assoc 1 aEntLst)) blkLst (cons (cons bEnt aVal) blkLst)))) (setq aEnt (entnext aEnt))))) (princ "\n<!> No Attributed Blocks Found <!>")) (alert (vl-princ-to-string blkLst)) (princ)) This function works great when the scale value has no white spaces; but when there is white spaces it only returns the right side of the scale value example 1 : SCALE 1:5 ==> Result = (( TitleBlockName. 1:5)) example 2 : SCALE 1 : 10 ==> Result = (( TitleBlockName. 1 : )) as you see in example 2 the return value is missing the right side value can you please help me with this issue to figure out why its returning the left side only? Edited December 2, 2014 by Muthanna Quote
BIGAL Posted December 2, 2014 Posted December 2, 2014 It may be easier to use layouts cut and paste the title block to a layout at true scale 1:1 and then use a mview window at scale the dimscale should still work. Maybe post a dwg would help to understand problem. Quote
Muthanna Posted December 2, 2014 Author Posted December 2, 2014 although I don't know what you mean to use layouts. But I should state that we need to perform this task on a batch of drawings automatically. I have had this code work perfectly until it came across some prints that have white spaces before and after the colon character in the scale attribute value. When I check the drawing manually by using command "ddatte" and then selecting the scale object, the window pops up and this window has the correct value of the scale. is there a better way to be able to read the scale value without losing any portion of it? Quote
SLW210 Posted December 2, 2014 Posted December 2, 2014 Please read the Code Posting Guidelines and edit your post to include the Code in Code Tags. Quote
Jef! Posted December 2, 2014 Posted December 2, 2014 It is funny because the code looks ok, I tried it and it works fine no matters what's Inside the attribute like.. "1:5" "1:10" " 1:10" " 1 : 10 " I also tried with multiple fields, spaces, combination of both and even tried addind wildcards (/\#?) and it worked perfectly fine. there is no "better way" as far as i see, because the code goes through all the attributes of all blocks, search for all the attributes named "scale". If there is one found, it update the returned list with a dotted pair containing the name of the block then the value contained Inside the attribute. The only thing I could saw is that you have 2 attributes, 1 named "SCALE" containing the value 1 : and another one (named differently) containing the denominator. Unfortunately reading your comment on when you check your value manually with ddatte, it made that hypothesis obsolete. Maybe if you post one drawing that dont work we could figure out something, because with the given information i'm clueless. Quote
Muthanna Posted December 3, 2014 Author Posted December 3, 2014 Hi Jef, Thank you for looking into this issue. I myself have tested this code with different combinations as well and they all work; but there are a few drawings that this is failing on. These drawing for some reason are giving wrong results as the one i specified in my post above. I m going to have some one look at these drawing and see why they are different and if they have some kind of special setting/attribute/tag that needs to be fixed! Quote
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.