Jump to content

Specifying a Particular DXF Code


Recommended Posts

Posted

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?

300dxfcodes.PNG

  • Replies 22
  • Created
  • Last Reply

Top Posters In This Topic

  • ksperopoulos

    11

  • cwake

    8

  • Lee Mac

    1

  • MSasu

    1

Top Posters In This Topic

Posted Images

Posted

Could you access the data more reliably by first using (member (assoc 300 elist) elist) to cut out the previous items in the list?

Posted

That's it!!!! Thank you. Sometimes the most obvious solutions can't be seen until someone else points them out. :D

Posted

Excellent. Wasn't sure if it would fit every case, but glad it did. :-D

Posted

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.

Posted

Another way to parse that list, independent of its length, is the FOREACH function.

Posted

So by using a massoc function, you are actually assigning a label to each 300 code, right?

Posted

More like assigning each 300 code to a key, creating a dotted pair for each item. (group 300 dxf code)

Posted

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

Posted

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?

Posted

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.

Posted

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?

Posted

Put it anywhere in your code as a sub-function. Then call it with your assoc list (massoc4 300 (entget ename)).

Posted

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?

Posted

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?

Posted

Yes, it makes sense. Thanks.

Posted

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.

Posted

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]
    )

Posted

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)))

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...