All Activity
- Past hour
-
Yes, that had some issues, I think I have that sorted, but not ready to repost. Still working on adding the DCL to it. It happens to me all of the time. No worries!
-
Why does using a variable for a T/nil outcome in an if statement make it go screwy?
SLW210 replied to ESan's topic in AutoLISP, Visual LISP & DCL
Please use Code Tags for your code in the future. (<> in the editor toolbar) -
jamami started following How to stop attributes from mirroring in nested blocks
-
How to stop attributes from mirroring in nested blocks
jamami posted a topic in AutoCAD Drawing Management & Output
I have recently updated a batch of blocks changing all labels from text to attributes, the idea being to stop them mirroring. After competing this task I find that the attribute text still mirrors. I think it is because the attributed blocks are nested. Is there any way to stop this? The attached block shows the issue. jam2.dwg -
Adding data to property lookup tables
jamami replied to jamami's topic in AutoCAD Drawing Management & Output
Hi This is a pretty complex block attached. All the parts are spaced out at mo while I am getting things working, once done they are all moved in line. We make beams 2,3,4,5&6m lengths. To make up 7m we use 4+3, to make up 8 we use 5+3, 9-5+4, 10-6+4, ....13-6+4+3 etc etc. i have defined the available viz states Issue is we terminate the beam ends in 1 of 3 ways also we run beams lengths upto 50m at times. Only 1 viz state allowed in autocad (although i did see a link containing a block with multiple viz states but i think that involves some pretty high end programming skills), so I have been playing with using dummy parameters. It works well (attached). My issue is that I need to create many many hundreds of lines of data to encompass the full range I am looking for . jam1.dwg -
ESan started following Why does using a variable for a T/nil outcome in an if statement make it go screwy?
-
After being stuck on this subject for a while, I know the answer is "don't use variables for the actions of an if statement" but I am still bothered as to WHY it does not work. I assume it has to do with the way the if function evaluates, but I cannot figure it out myself. I apologize in advance for the long read. For example, I created a short routine to give a positive or negative response dependent on whether or not the user input equals 1: (defun c:if (/ inp) (setq inp (getint "\nValue: ")) (if (= 1 inp) (print "You Did It!!!!!!!!!") (print "You FAILED") ) (princ) ) This routine works- I provide the action for the T or nil outcome within the if statement. However, if I assign variables instead: (defun c:if (/ inp yes no) (setq inp (getint "\nValue: ") yes (print "You Did It!!!!!") no (print "You FAILED") ) (if (= 1 inp) yes no) (princ) ) The routine doesn't know what to do with itself regardless of user input. It returns the nil outcome twice regardless of whether or not the user input value equals 1. I do not understand why it skips to the nil outcome if the statement is true.
- Today
-
After seeing your post I realized I was trying it with the wrong LISP. I was trying it with TMTMS and that was giving me the results that had the space and wasn't numbering anything. Just tried it with this one 'FNRSEQ' and it works perfectly. Thank you so much for this.
-
Thanks for this, learned something new, much cleaner and easier. I tried your suggestion, but didn't work, I also did some more testing and the reading of the data is done properly, the appending of the new content is done properly, and then I think the problem occurs when creating safearray using value 17 or in other words using VisualLisp variant data type vlax-vbByte, which is unsupported according to this post. So the value that has been returned from vlax-variant-type performed on result of reading with (LM:ReadBinaryStream (findfile "../AppAutoLoad.app") nil) is 8209 which is value of vlax-vbArray(8192) combined with vlax-vbByte(17), but since the vlax-vbByte data type seems to be unsupported I guess that I can't recreate the variant of the same type (8209) anymore?
-
Block definition modification - adding 2 attributes.
pefi replied to pefi's topic in .NET, ObjectARX & VBA
Thank you very much! I'm not sure if I understand you, you mean reading excel directly using AutoLISP? I never tried to do anything with excel and LISP together. When I have data in excel I use VBA and calling LISP scripts from VBA. The sample data set attached - there are 4 columns, file, bhd_ins - block handle that needs to get the "data injection", bhd_type and bhd_line - are the names of attributes in that block. The block handles in the sample set correspond to the real handles on the sample drawing. The content of bhd_type and bhd_line is made up, but that won't make a difference. sample_drawing.dwg handle_table.xlsx -
FWIW, you can change this: (mapcar 'ascii (MM:strToLst text)) To: (vl-string->list text) An untested suggestion: where the variant is concerned, rather than using hardcoded variant & safearray datatypes, try querying the types of the original variant & safearray using: vlax-variant-type vlax-safearray-type
-
Thanks for advice, I tried that already but no success, it seams like is not possible to write to binary files using standard write-line command. That's why I went from this solution from Lee Mac which is using ADO Stream object and it works fine when reading with LM:ReadBinaryStream and then writing the result of that function (whic is vlax-variant) back to the file using LM:WriteBinaryStream, but when I try creating my own vlax-variant object and write it back to the file it doesn't go as expected. Yes. it does, I'm using them in my code, but problem occurs while building vlax-variant object which is needed for writing data back to the file, somehow only zeroes are written and I can't figure out why.
-
increase or decrease value of attdef...help
BIGAL replied to leonucadomi's topic in AutoLISP, Visual LISP & DCL
Another go. (defun c:addval ( / lst lst2 att cnt lst3) (setq inc (getreal "\nEnter increment + or - ")) (setq ss (ssget '((0 . "TEXT,ATTDEF")))) (setq lst '() tnum 0 tatt 0) (repeat (setq x (sslength ss)) (setq obj (vlax-ename->vla-object (ssname ss (setq x (1- x))))) (setq objname (vlax-get obj 'objectname)) (if (= objname "AcDbText") (progn (setq newt (+ (atof (vlax-get obj 'textstring)) inc)) (cond ((< newt 10 ) (setq newt (strcat "00" (rtos newt 2 0)))) ((< newt 100) (setq newt (strcat "0" (rtos newt 2 0)))) (setq newt (rtos newt 2 0)) ) (vlax-put obj 'textstring newt) (setq tnum (1+ tnum)) ) (progn (setq newt (+ (atof (vlax-get obj 'tagstring)) inc)) (cond ((< newt 10) (setq newt (strcat "00" (rtos newt 2 0)))) ((< newt 100) (setq newt (strcat "0" (rtos newt 2 0)))) (setq newt (rtos newt 2 0)) ) (vlax-put obj 'tagstring newt) (setq tatt (1+ tatt)) ) ) ) (alert (strcat (rtos tnum 2 0) " text changed \n" (rtos tatt 2 0) " tags Changed")) (princ) ) -
Hiding LISP code in CUI button
Strydaris replied to Strydaris's topic in The CUI, Hatches, Linetypes, Scripts & Macros
@CivilTechSource Yes you can make the variable global by not clearing it in the lisp routine. If you aren't familiar with what I am taking about in a lisp you write at the top this.. (defun c:lisp ( / variable1 variable2) ) If you set a value to variable3 as long as it's not in the list like variable1 is then it's consider a global variable which can be used by multiple lisps. Typically I see people use something like global:variable1 to know which is which. Hope that helps. -
Block definition modification - adding 2 attributes.
BIGAL replied to pefi's topic in .NET, ObjectARX & VBA
You mention reading from Excel, its not a problem you can read cells from CAD, so if you have multiple blocks can be done. It would be simple to add to your defun say two columns in Excel Blocknames & dwgname with path. Need a sample Excel. -
Hiding LISP code in CUI button
BIGAL replied to Strydaris's topic in The CUI, Hatches, Linetypes, Scripts & Macros
A suggestion use a "\n" in the (getreal "\nEnter Rise...) this will push a new line on the command line. If the F2b is a global variable then any lisp can read it, but that is not necessarily a good idea. Its easier to do a double lisp in the cui. So load the program and call a defun passing it the f2b value. ^C^C^P(setq F2B (getreal "Enter Rise for Front to Back slopes: "))(load "mylisp")(mylisp f2b) I use LDATA when I want values stored in a dwg they stay in the dwg and can be changed. -
CUI Input Text Field?
BIGAL replied to CivilTechSource's topic in The CUI, Hatches, Linetypes, Scripts & Macros
You can have lisp in a CUI I have set a variable then load a lisp using that variable. Simple answer ^c^C^p(setvar 'textsize (getreal "\nEnter text height "))(load "mylisp") There is a textbox input trying to remember it someone else will post. It is a built in function. Or can do something like this, another DCL example is at Afralisp. ^c^c^p(if (not AH:getvalsm)(load "Multi Getvals.lsp"))(setq ans (AH:getvalsm (list "Enter text height " "height" 5 4 "2.5")))(load "mylisp") Multi GETVALS.lsp -
Adding data to property lookup tables
BIGAL replied to jamami's topic in AutoCAD Drawing Management & Output
I think we are struggling to see what you want, if you type 1-2-3 as entry its easy to split it apart based on the "-" into 3 variables . Maybe make a movie if you don't want to post the block. - Yesterday
-
Works fine on your drawing here. Post that drawing if possible, looks like something in the Mleader MText. Post the command line as well. Command: FNRSEQ Enter FIND text: 03 Enter starting REPLACE number (e.g. 01): 01 Enter line number for MTEXT/Multileader (or type 'All'): 1 Select objects: 1 found Select objects: 1 found, 2 total Select objects: Specify opposite corner: 0 found Select objects: 1 found, 3 total Select objects: 1 found, 4 total Select objects: Sequential find & replace completed.
-
mhupp started following Read/Write Binary Files
-
Rather then reading the file and then writing it back with new data added just open the file in append mode. aka add the data you want at the end. ;; Example usage: ;; (MH:AppendText "C:/path/to/your/file.txt" "This is a new line of text") (defun MH:AppendText (filename text / file) (vl-load-com) (setq file (open filename "A")) 'open file in append (if file (progn (write-line text file) (close file) (princ (strcat "\nText appended to " filename)) ) (princ (strcat "\nError: Could not open " filename)) ) (princ) ) also ZWCAD might now be able to use some of the Visualisp commands like vlax- and vl-
-
increase or decrease value of attdef...help
leonucadomi replied to leonucadomi's topic in AutoLISP, Visual LISP & DCL
You can add something like this to make the numbering 3 digits? like this (setq i 1 ) (foreach sub lst (setq lent (entget (last sub)) txt (strcat (if (< i 10) "00" (if (< i 100) "0" "")) (itoa i)) i (1+ i) ) (entmod (subst (cons 1 txt)(assoc 1 lent) lent)) ) -
increase or decrease value of attdef...help
leonucadomi replied to leonucadomi's topic in AutoLISP, Visual LISP & DCL
This tool is great but I need the numbering to be in this format 001, 050....I mean that a zero accompanies the number la numeracion que aqui manejamos usa 3 digitos -
Lee Mac started following Read/Write Binary Files
-
Hello friends i have in attached drawing 2 3dfaces i want to apply command loft on first one and second one but when selecting first 3d face it rejected and said invalid object i was filtered out but when moving or copying this object to some other places it worked so i want an explanation of what is happening loft on 3dface.dwg
-
Tried this one and think I'm doing it correctly but am getting a weird outcome. I enter 03 to be the text to find and 01 the text to replace it with and it numbered them sequentially but placed a space between the 0 and 1. Also I tried it again but put 08 as the replace text and it gave me the same this as if I had put 01 for the replace text.
-
Fidelojo started following Read/Write Binary Files
-
Hi, so I'm using ZWCAD and it has a file called 'AppAutoLoad.app' which stores all script files paths from Startup Suite. If I paste new path in it it works fine, accepts it and loads it upon next running of CAD software but it seams to be a binary file because when I write to it using write-line command some weird characters are written. I tried writing content to it using LISP scripts provided here by Lee Mac and it work fine when using both functions together, the content is read as a variant and that variant has been written back like this: (LM:WriteBinaryStream (findfile "../AppAutoLoad.app") (LM:ReadBinaryStream (findfile "../AppAutoLoad.app") nil)) So that worked fine in ZWCAD, but when I tried constructing variant object on my own it won't work, I tried looking on multiple forums, reading docs I could find about it, but I can't make it work, this is the function I made for appending new content to the file: (defun MM:AppendToBinaryFile ( path text / fileData ) (setq text (mapcar 'ascii (MM:strToLst text)) ; Converting text to list of corresponding ASCII values fileData (vlax-variant-value (LM:ReadBinaryStream path nil))) ; Reading variant value of the existing file data (if fileData ; Check if there is any existing data (setq fileData (reverse (vlax-safearray->list fileData))) ; Convering data to list of ASCII values and reversing it for appending new values ) (foreach letter text (setq fileData (cons letter fileData)) ; Adding every new character to the existing data ) (setq fileData (reverse fileData) ; Reversing values to restore proper order vlax-vbByte 17 ; Setting value for non-existing variant type byte-array (vlax-make-safearray vlax-vbByte (cons 0 (1- (length fileData))))) ; Creating empty safearray of appropriate size (vlax-safearray-fill byte-array fileData) ; Filling safearray with full data (old + new) (setq fileData (vlax-make-variant byte-array (+ vlax-vbArray vlax-vbByte))) ; Creating variant object (LM:WriteBinaryStream path fileData) ; Writting data back to file (princ) ) Also MM:strToLst is just a function that splits string into list of characters, I'll post it if someone needs it for testing: (defun MM:strToLst ( str / ) (if (> (strlen str) 0) (cons (substr str 1 1) (MM:strToLst (substr str 2))) nil ) ) Can anyone help on this topic or point on some error in my code? I did some testing and final safearray seems to keeps containing zeroes only even after filling it but I don't know why is that, I tried to fix it somehow but without success. I am also sending the file I am working with. After reading the content, vlax-variant-type command gives me code 8209. AppAutoLoad.app
-
I will try that one out as well. Haven't been able to get back on here too often to try everything out because of my workload as well. I would be very interested to see the LISP with the dialog box as well. Thanks for all your help.
-
This worked for me as well.