ksperopoulos Posted February 5, 2014 Posted February 5, 2014 I am having troubles with handling a particular DXF code. The item in the model I am selecting has multiple 300 DXF codes. The only way I have found i am able to pull information from them, is to use the nth function. This has proven to be unstable since the information before these codes may vary depending on its current properties. I know I can keep the 300 DXF codes in a particular sequence, but is there a method of finding a particular 300 code without using the nth function? Quote
cwake Posted February 5, 2014 Posted February 5, 2014 Could you access the data more reliably by first using (member (assoc 300 elist) elist) to cut out the previous items in the list? Quote
ksperopoulos Posted February 5, 2014 Author Posted February 5, 2014 That's it!!!! Thank you. Sometimes the most obvious solutions can't be seen until someone else points them out. Quote
cwake Posted February 5, 2014 Posted February 5, 2014 Excellent. Wasn't sure if it would fit every case, but glad it did. :-D Quote
ksperopoulos Posted February 5, 2014 Author Posted February 5, 2014 I still have to use the nth function, but I can control the number of 300 codes and their order - therefore, I now have more stability. Thanks again. Quote
MSasu Posted February 5, 2014 Posted February 5, 2014 Another way to parse that list, independent of its length, is the FOREACH function. Quote
Lee Mac Posted February 5, 2014 Posted February 5, 2014 Use a 'massoc' function, and then process the list of DXF group 300 values as necessary. Quote
ksperopoulos Posted February 6, 2014 Author Posted February 6, 2014 So by using a massoc function, you are actually assigning a label to each 300 code, right? Quote
Bhull1985 Posted February 6, 2014 Posted February 6, 2014 More like assigning each 300 code to a key, creating a dotted pair for each item. (group 300 dxf code) Quote
cwake Posted February 6, 2014 Posted February 6, 2014 Like bhull said. So it isolates all dotted pairs that have a car of 300. So you could have other group codes following the 300 ones, the massoc function would cut those out as well, leaving only the 300 ones. Examine the quickest of the functions that Lee posted, MASSOC4. It uses the same technique as I suggested above, but is a neat application of recursion. It will repeat calling itself until there are no more 300 dotted pairs. Then it "unwinds" resulting in a list of only 300 dotted pairs Quote
ksperopoulos Posted February 6, 2014 Author Posted February 6, 2014 It sounds like I will still have to use the nth function to retrieve the desired result, right? The massoc will just strip all my options down to just the 300 dotted pairs so I don't mistakenly pick an incorrect option outside the 300 group? Quote
cwake Posted February 6, 2014 Posted February 6, 2014 Yes. And assumably that data is constant and always in the same order. I can't see any other way to differentiate it in the example you first posted. Quote
ksperopoulos Posted February 6, 2014 Author Posted February 6, 2014 OK. Thank you. I just wanted to make sure I understand it correctly. So the massoc is a subfunction that can go in the code anywhere or does it need to be located where I need to use it within my program? Quote
cwake Posted February 6, 2014 Posted February 6, 2014 Put it anywhere in your code as a sub-function. Then call it with your assoc list (massoc4 300 (entget ename)). Quote
ksperopoulos Posted February 6, 2014 Author Posted February 6, 2014 I keep getting this error message whenever I use it. Could this be affecting the rest of my code? Error: bad argument type: consp "90 LR" Edit: Nevermind. I was trying to use (cdr (nth 4 (massoc4 300 elist))). I guess the cdr function is already being used in the massoc sub-function so I don't need it again in the other part of the code. Thank you all for the help! BTW-does the 4 at the end of massoc4 mean anything? Can I just use massoc? Quote
cwake Posted February 6, 2014 Posted February 6, 2014 Good pickup. My choice of words may have mislead you on that, because I had not looked at the construct of the returned list. Sorry. As for the function name, you can name it massoc, just be sure if you used a recursive function like MASSOC4 that you rename where it calls itself as well. Hope that makes sense? Quote
ksperopoulos Posted February 6, 2014 Author Posted February 6, 2014 Yes, it makes sense. Thanks. Quote
ksperopoulos Posted February 7, 2014 Author Posted February 7, 2014 OK, here is a different scenario, but still along the same subject. I have multileaders that use blocks with attributes. I am trying to get the value of those attributes. From the help file, the DXF code for MLEADERS' "Block Attribute Text String" is 302. Well when you run (entget (car (entsel))) on a single multileader, there are two 302 values. The first 302 value is (302 . "LEADER{"), while the second 302 value is what I am really looking for. I can use the same massoc subfunction to extract the value, but I'm thinking there is a better way that some of you more experienced programmers could point me to. Quote
cwake Posted February 7, 2014 Posted February 7, 2014 This is what I've been doing. Again it uses the combination of member and assoc. I assume that you are only wanting to extract the text string, not replace it? Because if you want to replace it I usually extract the object ID in the same while loop. ;get the attributes for the block (setq tmp1 (member (assoc 344[color=black] elist[/color]) elist))[color=red] ;cut out the irrelevant (and duplicated car) earlier codes[/color] (while (setq tmp1 (member (assoc 330 tmp1) tmp1)) (setq attdata (cons (list (cdr (assoc 177 tmp1))[color=red] ;attribute number - this becomes important if the text has fields in it[/color] (cdr (assoc 302 tmp1))[color=red] ;the attribute string itself[/color] (= (cdr (assoc 101 (entget (cdr (assoc 330 tmp1))))) "Embedded Object")[color=red] ;single or multiline attribute - this becomes important if you want to know which formatting strings might be present[/color] ) attdata ) tmp1 (cdr tmp1) ) );while ;if attributes (if attdata [color=blue]....process them[/color] ) Quote
cwake Posted February 7, 2014 Posted February 7, 2014 I should add that the code above is written for when you might have multiple attributes in the multileader block. It will work with one attribute, but it will also work with a hundred. If you know that you are only interested in one, you could simplify it to. (cdr (assoc 302 (member (assoc 344[color=black] elist[/color]) elist))) 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.