See the top rated post in this thread. Click here

Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: cycle through an entity with multiple dxf codes

  1. #1
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,198
    Login to Give a bone
    0

    Default cycle through an entity with multiple dxf codes

    I dont know how best to title this, but I want to know how to cycle through an entity that has multiple parts and duplicate dxf codes, for example, I want to search a table for a dxf code 1 whose second part is a wild card match of "{*" , then modify the text and replace it in the table.
    Or filter out all the vertex points in a polyline to create a list of vertexes.

  2. #2
    I could stop if I wanted to tyshofner's Avatar
    Join Date
    2004-03
    Location
    Dallas, Tx
    Posts
    229
    Login to Give a bone
    0

    Default Re: cycle through an entity with multiple dxf codes

    Two Examples

    First collects polyline vertices:

    Code:
     
    (setq ent (entget (car (entsel)))) 
    (setq vertex_lst (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) ent)))
    Second will parse through the entity list looking for dxf code 1, then run the wcmatch and execute code if needed:

    Code:
     
    (setq ent (entget (car (entsel)))) 
    (foreach dp ent
    (if (= (car dp) 1)
    (if (= (wcmatch (cdr dp) "{*") T)
    (progn
    	;***YOUR CODE HERE**;
    	;***YOUR CODE HERE**;
    	;***YOUR CODE HERE**;
    )
    )
    )
    )
    Ty
    Last edited by tyshofner; 2007-05-23 at 11:53 PM.

  3. #3
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,198
    Login to Give a bone
    0

    Default Re: cycle through an entity with multiple dxf codes

    so if I wanted to replace the contents of the dxf code, I would use the following?

    Code:
       (progn
    	 (setq leftside (vla- "{`abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ|0123456789" (cdr dp)))
    	leftside2 (vla ";" leftside)
    	rightside (vla "}" leftside2)
    	)
    	 (setq Ent (subst (cons 1 rightside) dp Ent))
    	 (entmod Ent)
    	 );end progn

  4. #4
    I could stop if I wanted to tyshofner's Avatar
    Join Date
    2004-03
    Location
    Dallas, Tx
    Posts
    229
    Login to Give a bone
    0

    Default Re: cycle through an entity with multiple dxf codes

    Yes, the "subst" & "entmod" functions will replace the string. I'm assuming that the "vla" function you have in your code is a user sub-routine if this is correct than yes this should work. One thing I will point out:

    Although "entmod" modifies the entity list, you still need to "update" the entity grachically. To do this you must use "entupd". You could just regen at the end of the routine, but why have acad redraw everything when you can have it just do the one entity. See below:

    Code:
    (progn
    (setq leftside (vla- "{`abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ|0123456789" (cdr dp)))
    leftside2 (vla ";" leftside)
    rightside (vla "}" leftside2)
    )
    (setq Ent (subst (cons 1 rightside) dp Ent))
    (entmod Ent)
    (entupd (cdr (assoc -1 Ent)))
    );end progn
    Ty

  5. #5
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,198
    Login to Give a bone
    0

    Default Re: cycle through an entity with multiple dxf codes

    sorry, vla was supposed to be vl-string-left-trim, I couldnt remember the proper function at the time, so it was just a place holder I think I have my program running now, I will post it as soon as I have done more testing. When it is done, people will be able to use it to strip a table back to default formatting.

  6. #6
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,198
    Login to Give a bone
    1

    Default Re: cycle through an entity with multiple dxf codes

    feel free to modify it, it is probably pretty crude by programming standards, maybe someone could help me clean it up. all it does right now is just convert the text style back to the table's text style.

    Thanks for your help Ty

    Code:
    (defun c:striptable
    	(/ BlName EntName EntDxf dp leftside leftside2 rightside)
    	 (setq BlName (ssget '((0 . "ACAD_TABLE")))
    	 EntName (ssname BlName 0)
    	 EntDxf (entget Entname)
    	 ) ;_ end of setq
    	 (foreach dp EntDxf
    (if (= (car dp) 1)
    (if (= (wcmatch (cdr dp) "`{*") T)
    	 (progn
    	 (setq leftside (vl-string-left-trim
    	"{\\abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ|0123456789 "
    	(cdr dp)
    		 ) ;_ end of vl-string-left-trim
    	 leftside2 (vl-string-left-trim ";" leftside)
    	 rightside (vl-string-right-trim "}" leftside2)
    	 ) ;_ end of setq
    	 (setq EntDxf (subst (cons 1 rightside) dp EntDxf))
    	 (entmod EntDxf)
    	 (entupd (cdr (assoc -1 EntDxf)))
    	 )	;end progn
    )	;end if
    )	;end if
    (if (= (car dp) 302)
    (if (= (wcmatch (cdr dp) "`{*") T)
    	 (progn
    	 (setq leftside (vl-string-left-trim
    	"{\\abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ|0123456789 "
    	(cdr dp)
    		 ) ;_ end of vl-string-left-trim
    	 leftside2 (vl-string-left-trim ";" leftside)
    	 rightside (vl-string-right-trim "}" leftside2)
    	 ) ;_ end of setq
    	 (setq EntDxf (subst (cons 302 rightside) dp EntDxf))
    	 (entmod EntDxf)
    	 (entupd (cdr (assoc -1 EntDxf)))
    	 )	;end progn
    )	;end if
    )	;end if
    	 )	 ;end foreach
    	 (princ)
    	) ;_ end of defun

  7. #7
    Active Member nelson's Avatar
    Join Date
    2015-11
    Location
    Portland, MI
    Posts
    93
    Login to Give a bone
    0

    Default Re: cycle through an entity with multiple dxf codes

    This does exactly what it says, but I have one problem. If you have a datalinked table, it strips the link out to the table.

  8. #8
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: cycle through an entity with multiple dxf codes

    Maybe if you use the vla functions to edit the contents of the table instead of entmod, it won't break the datalink. E.g.
    Code:
    (setq EntObj (vlax-ename->vla-object EntName))
    (setq ColCount (vla-get-Columns EntObj)) ; Gets the number of columns
    (setq RowCount (vla-get-Rows EntObj)) ; Gets the number of rows
    (vla-GetCellValue EntObj 2 5) ;Gets value of 2nd row 5th column
    (vla-SetCellValue EntObj 6 10 NewVal) ;Sets the cell in 6th row 10th column to the string contained in NewVal
    Just a thought though ... if you're changing a value inside a table linked to attributes / excel - wouldn't that in itself break the link?

  9. #9
    Active Member nelson's Avatar
    Join Date
    2015-11
    Location
    Portland, MI
    Posts
    93
    Login to Give a bone
    0

    Unhappy Re: cycle through an entity with multiple dxf codes

    First, I think that I need to think about how I used this. I'm pretty new to working with code, so I don't think that I understood what this did.

    What I did was use this on an Autocad Table to reset the font styles to an Autocad font, and this table was datalinked back to excel. Does that make sense? Excel used a TTF font like Arial, and Autocad has a curent style of simplex.shx. So what I thought this would do is strip the table back to the Autocad Table style, which it did, but then stripped the link away from the table.
    I'm reading this whole post again, and lookin at the OP, this has nothing do do with a "Table" but more of the internal code of Autocad's table of entities. Right?

    But it worked all the same, but lost the datalink.

    So irneb, are you telling me that you see a way to strip the Autocad Table back to a table style, and not lose the datalink?

    If what I'm doing, (second paragraph), is not what this code is for, someone let me know and I'll know that I'm going down the wrong track for my problem. I don't want to cause confusion, and get unrelated code put in this post.

  10. #10
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,198
    Login to Give a bone
    0

    Default Re: cycle through an entity with multiple dxf codes

    My original post was formatted generally so I could hopefully apply the knowledge I gained to more than one application. But then I posted the table strip command, because that is what I was working on, and why I needed the information. Kind of like, here is how I used this knowledge I obtained from you. If you could post the entdata for a linked table, I could possibly help modify the strip command so it will only strip formatting, not a link. Use this command, select the object, copy the command line content and paste it back here.
    Code:
    (defun select (/ object objent objentdata)
      (setq    object       (ssget)
        objent       (ssname object 0)
        objentdata (entget objent)
      ) ;_ end of setq
    ) ;_ end of defun
    to call the above command use: (select)

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 24
    Last Post: 2007-03-14, 06:00 AM
  2. About <Cycle On> and <Cycle Off>
    By vkotesh in forum AutoCAD General
    Replies: 1
    Last Post: 2006-01-23, 12:34 PM
  3. Proxy Entity Code 310 to Normal Entity
    By KevinBarnett in forum AutoCAD General
    Replies: 2
    Last Post: 2005-05-26, 07:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •