Author Topic: [Newb Help] Filter Objects using dxf code value  (Read 6320 times)

0 Members and 1 Guest are viewing this topic.

James Cannon

  • Guest
[Newb Help] Filter Objects using dxf code value
« on: May 01, 2009, 03:17:25 PM »
Code: [Select]
(setq ss(ssget "_X" (list (cons 0 "ACAD_PROXY_ENTITY"))))
I had to trouble shoot that line a few times to get it to work, it always gave be "Bad SSGET list" until I made it as you see above.  Now I get:


Quote
Command: ; error: bad argument type: lselsetp nil

However, I have no idea where to look to figure out what's wrong :(

Here is the entire .lsp, for context.

I define the function "SurveyCleaner" first, then define a function, "pointfix" that creates a selection set of all AUTOCAD_PROXY_ENTITY 's in the drawing, and for each of them, runs "SurveyCleaner" but I assume my programming logic fails somewhere, and something is not doing what I think it's going to do.... I just have no idea what :(

Code: [Select]
(defun SurveyCleaner()

;;;--- ACTIONS TO BE EXECUTED FOR EACH ITEM SELECTED IN THE 'PointFix' routine below
(setq number(ssget "_X" '((62 . 4)(8 . "PT")))) ;;;---selection set of objects color 'cyan' layer PT
(setq elev(ssget "_X" '((62 . 7)(8 . "PT")))) ;;;---selection set of objects color 'white' layer PT
(setq desc(ssget "_X" '((62 . 3)(8 . "PT")))) ;;;---selection set of objects color 'green' layer PT
(setq node(ssget "_X" '((62 . 256)(8 . "PT")))) ;;;---selection set of objects color 'ByLayer' layer PT

(setq numEL (entget number))
(setq eleEL (entget elev))
(setq desEL (entget desc))
(setq nodEL (entget node))

;;;--- CREATE 'NEWNUMBER'
(setq newnumber(list
(cons 0 "MTEXT")
(cons 8 "SRVY-POINT-No")
(cons 100 "AcDbMText")
(cons 62 "256")
(cons 7 "SurveyData")
(cons 40 12.0)
(cons 41 1.0)
(cons 42 1.0)
(cons 50 0.0)
(cons 73 1.0)
(cons 10 (cdr (assoc 10 numEL)))
(cons 1 (cdr (assoc 1 numEL)))
)
)
(entmake newnumber)


;;;--- CREATE 'NEWELEV'
(setq newelev(list
(cons 0 "MTEXT")
(cons 8 "SRVY-POINT-ELEV")
(cons 100 "AcDbMText")
(cons 62 "256")
(cons 7 "SurveyData")
(cons 40 12.0)
(cons 41 1.0)
(cons 42 1.0)
(cons 50 0.0)
(cons 73 1.0)
(cons 10 (cdr (assoc 10 eleEL)))
(cons 1 (cdr (assoc 1 eleEL)))
)
)
(entmake newelev)




;;;--- CREATE 'NEWDESC'
(setq newdesc(list
(cons 0 "MTEXT")
(cons 8 "SRVY-POINT-DESC")
(cons 100 "AcDbMText")
(cons 62 "256")
(cons 7 "SurveyData")
(cons 40 12.0)
(cons 41 1.0)
(cons 42 1.0)
(cons 50 0.0)
(cons 73 1.0)
(cons 10 (cdr (assoc 10 desEL)))
(cons 1 (cdr (assoc 1 desEL)))
)
)
(entmake newdesc)
;;;--- CREATE 'NEWNODE'
(setq newnode(list
(cons 0 "MTEXT")
(cons 8 "SRVY-POINT-No")
(cons 100 "AcDbMText")
(cons 62 "256")
(cons 7 "SurveyData")
(cons 40 12.0)
(cons 41 1.0)
(cons 42 1.0)
(cons 50 0.0)
(cons 73 1.0)
(cons 10 (cdr (assoc 10 nodEL)))
(cons 1 (cdr (assoc 1 nodEL)))
)
)
(entmake newnode)
(princ)
)

;;;------------------------------------
;;;------------------------------------
;;;------------------------------------

(defun C:pointfix()
;;;--- CREATE NEW LAYERS REQUIRED
(command "-style" "SurveyData" "RomanS" 0 1 0 "No" "No" "No")
(command "-layer" "m" "SRVY-POINT-No" "C" 7 "" "")
(command "-layer" "m" "SRVY-POINT-ELEV" "C" 32 "" "")
(command "-layer" "m" "SRVY-POINT-DESC" "C" 52 "" "")
(command "-layer" "m" "SRVY-POINT-NODE" "C" 62 "" "")
(command "-layer" "m" "SRVY-TEMP-PT" "C" 3 "" "")

;;;--- GET SELECTION SET OF EXISTING SURVEY POINTS AND ASSIGN IT TO SOMETHING TO BE CALLED
(setq ss(ssget "_X" (list (cons 0 "ACAD_PROXY_ENTITY"))))

;;;--- BEGIN WHILE LOOP TO RUN TYPICAL ACTIONS
(while (< (sslength eset)) SurveyCleaner)
(princ)
)

James Cannon

  • Guest
Re: [Newb Help] Filter Objects using dxf code value
« Reply #1 on: May 01, 2009, 03:25:41 PM »
I'm mainly hoping to get an educated pair of eyes on what I'm doing, hoping some guiding light could be shed on my work :\

To explain what I'm trying to do:

I get a survey file that has point data as proxy entities, and I want to create a survey that we can work better with, turn off layers, etc.  As it is, all objects are on one layer, different colors, and all around a PITA to work with if we want to view it differently.

My boss decided the easiest thing to do in the whole situation was task me with creating a routine to take the surveyors points in CAD, and modify them. 

The surveyor -does- send us an .asc file with raw point data, but I only just now realized this, and I'm already a good ways invested in the route I've chosen, so I hammer on.

I wish to do this to each entity:

explode it, select the 'cyan' entity which is an mtext object containing the point #, and create a new piece of mtext with insertion point and content matched to the old, and all other properties (layer, color, textstyle, etc) as I see fit.

mimic that for green entity, and white entity.

Then I wish to repeat that process for each and every AUTOCAD_PROXY_ENTITY in the drawing.

Then, I won't be at 100% done, but will be mostly there.


mkweaver

  • Bull Frog
  • Posts: 352
Re: [Newb Help] Filter Objects using dxf code value
« Reply #2 on: May 01, 2009, 04:11:40 PM »
James,
First off, in this section:
Code: [Select]
(setq numEL (entget number))
(setq eleEL (entget elev))
(setq desEL (entget desc))
(setq nodEL (entget node))
You are calling entget on a selection set, when it expects an entity name.  Try this instead:
Code: [Select]
(setq numEL (entget (ssname number 0)))
(setq eleEL (entget (ssname elev 0)))
(setq desEL (entget (ssname desc 0)))
(setq nodEL (entget (ssname node 0)))

However, what I've given, above, does no checking in case there was nothing selected.

James Cannon

  • Guest
Re: [Newb Help] Filter Objects using dxf code value
« Reply #3 on: May 01, 2009, 04:14:12 PM »
I see.  I am still very rough and unstable with understanding exactly what some of these things expect.

I have updated my routine with those changes.  Thank you for the input!

I really don't have -any- error trapping or 'checks' ... which may be why this is so hard for me as yet, but i was afraid, in my incompetence, that I would introduce further errors, if I error trapped improperly, and that it would confuse me further, and end up doing more harm than good. 

mkweaver

  • Bull Frog
  • Posts: 352
Re: [Newb Help] Filter Objects using dxf code value
« Reply #4 on: May 01, 2009, 04:25:27 PM »
I see.  I am still very rough and unstable with understanding exactly what some of these things expect.

I have updated my routine with those changes.  Thank you for the input!

I really don't have -any- error trapping or 'checks' ... which may be why this is so hard for me as yet, but i was afraid, in my incompetence, that I would introduce further errors, if I error trapped improperly, and that it would confuse me further, and end up doing more harm than good. 

I understand your concerns about error checking introducing problems, though more often it simply hides them.  If you do your development in the visual lisp IDE and use breakpoints and step through your code with a watch window, you can typically tell where your errors are and, with a bit of practice, learn to decipher the error messages.

Keep the questions coming.

Mike

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: [Newb Help] Filter Objects using dxf code value
« Reply #5 on: May 01, 2009, 04:32:26 PM »
The while loop isn't doing anything ....that is it wouldn't if you got past the error of "lselsetp nil" which is occurring due to this:
(while (< (sslength eset)) ... you defined your Selection Set to be ss, not eset

Once that is fixed, you still need to get the (while) to do something...more like so:
Code: [Select]
(while (< 0 (sslength ss))
  (command "explode" (ssname ss 0))
  (surveycleaner)
  (ssdel (ssname ss 0) ss)
)

James Cannon

  • Guest
Re: [Newb Help] Filter Objects using dxf code value
« Reply #6 on: May 01, 2009, 04:53:49 PM »
grr.

I see what I did there.

I see what you did, and that makes much sense, JeffM.  Thank you.  Most of my stuff is "shootin' from the hip" unfortunately.

I see.  I am still very rough and unstable with understanding exactly what some of these things expect.

I have updated my routine with those changes.  Thank you for the input!

I really don't have -any- error trapping or 'checks' ... which may be why this is so hard for me as yet, but i was afraid, in my incompetence, that I would introduce further errors, if I error trapped improperly, and that it would confuse me further, and end up doing more harm than good. 

I understand your concerns about error checking introducing problems, though more often it simply hides them.  If you do your development in the visual lisp IDE and use breakpoints and step through your code with a watch window, you can typically tell where your errors are and, with a bit of practice, learn to decipher the error messages.

Keep the questions coming.

Mike

Shoot, I hadn't even thought of that.  I should have... I was used to stepping through VBA code that way, but I have been working in notepadd++ for the LISP heh... I shall swap over.

James Cannon

  • Guest
Re: [Newb Help] Filter Objects using dxf code value
« Reply #7 on: May 01, 2009, 05:09:14 PM »
Ok, so I'm having trouble with:
   
Code: [Select]
(cons 10 (cdr (assoc 10 numEL)))
What I want is to take the value of the dxfcode 10 from the entity I assigned as 'numEL' which is a selection set defined here:
Code: [Select]
(setq numEL (entget (ssname number 0)))
Should that not satisfy the (assoc element alist) ?

If I understand right, I'm giving it 'numEL' which is the association list of 'number'

So if I am telling it to construct a dotted list, (10 . [using cdr to return everything past the first value of the dxf group code 10])

I don't understand why it breaks :(

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: [Newb Help] Filter Objects using dxf code value
« Reply #8 on: May 01, 2009, 05:23:05 PM »
Can you post a small sample dwg?

Or, if you want to troubleshoot it yourself, get to stepping through the code in the VLIDE with a watch on those variables. You will/should quickly find the source of the problem.

James Cannon

  • Guest
Re: [Newb Help] Filter Objects using dxf code value
« Reply #9 on: May 01, 2009, 05:32:27 PM »
heh, I admit, I couldn't get the VLIDE to work for me... 'step into' is greyed out and I have no idea how to use this thing, tbh.

It just shot out
Code: [Select]
Command: ; error: bad DXF group: (10)
I saw what I did though, it was a stupid mistake I wasn't paying attention to.

I got it to run "successfully" without error, though the results are not what I desired, completely.

I'm going to see what I can do with it, and may be back if I get stuck.

Thank you so much so far, for everything by the way, everyone.

James Cannon

  • Guest
Re: [Newb Help] Filter Objects using dxf code value
« Reply #10 on: May 01, 2009, 05:41:00 PM »
sample I'm working with attached:

and what I'm working with at the moment:
Code: [Select]
(defun SurveyCleaner()

;;;--- ACTIONS TO BE EXECUTED FOR EACH ITEM SELECTED IN THE 'PointFix' routine below
(setq number(ssget "_X" '((62 . 4)(8 . "PT")))) ;;;---selection set of objects color 'cyan' layer PT
(setq elev(ssget "_X" '((62 . 7)(8 . "PT")))) ;;;---selection set of objects color 'white' layer PT
(setq desc(ssget "_X" '((62 . 3)(8 . "PT")))) ;;;---selection set of objects color 'green' layer PT
(setq node(ssget "_X" '((62 . 256)(8 . "PT")))) ;;;---selection set of objects color 'ByLayer' layer PT

(setq numEL (entget (ssname number 0)))
(setq eleEL (entget (ssname elev 0)))
(setq desEL (entget (ssname desc 0)))
(setq nodEL (entget (ssname node 0)))

;;;--- CREATE 'NEWNUMBER'
(setq newnumber(list
(cons 0 "MTEXT")
(cons 8 "SRVY-POINT-No")
(cons 100 "AcDbMText")
(cons 62 256)
(cons 7 "SurveyData")
(cons 40 12.0)
(cons 41 1.0)
(cons 42 1.0)
(cons 50 0.0)
(cons 10 (cdr (assoc 10 numEL)))
(cons 1 (cdr (assoc 1 numEL)))
)
)
(entmake newnumber)


;;;--- CREATE 'NEWELEV'
(setq newelev(list
(cons 0 "MTEXT")
(cons 8 "SRVY-POINT-ELEV")
(cons 100 "AcDbMText")
(cons 62 256)
(cons 7 "SurveyData")
(cons 40 12.0)
(cons 41 1.0)
(cons 42 1.0)
(cons 50 0.0)
(cons 10 (cdr (assoc 10 eleEL)))
(cons 1 (cdr (assoc 1 eleEL)))
)
)
(entmake newelev)




;;;--- CREATE 'NEWDESC'
(setq newdesc(list
(cons 0 "MTEXT")
(cons 8 "SRVY-POINT-DESC")
(cons 100 "AcDbMText")
(cons 62 256)
(cons 7 "SurveyData")
(cons 40 12.0)
(cons 41 1.0)
(cons 42 1.0)
(cons 50 0.0)
(cons 10 (cdr (assoc 10 desEL)))
(cons 1 (cdr (assoc 1 desEL)))
)
)
(entmake newdesc)

;;;--- CREATE 'NEWNODE'
(setq newnode(list
(cons 0 "POINT")
(cons 8 "SRVY-POINT-NODE")
(cons 100 "AcDbEntity")
(cons 62 256)
(cons 10 (assoc 10 nodEL))
)
)
(entmake newnode)
(princ)
)

;;;------------------------------------
;;;------------------------------------
;;;------------------------------------

(defun C:pointfix()
;;;--- CREATE NEW LAYERS REQUIRED
(command "-style" "SurveyData" "RomanS" 0 1 0 "No" "No" "No")
(command "-layer" "m" "SRVY-POINT-No" "C" 7 "" "")
(command "-layer" "m" "SRVY-POINT-ELEV" "C" 32 "" "")
(command "-layer" "m" "SRVY-POINT-DESC" "C" 52 "" "")
(command "-layer" "m" "SRVY-POINT-NODE" "C" 62 "" "")
(command "-layer" "m" "SRVY-TEMP-PT" "C" 3 "" "")

;;;--- GET SELECTION SET OF EXISTING SURVEY POINTS AND ASSIGN IT TO SOMETHING TO BE CALLED
(setq ss(ssget "_X" (list (cons 0 "ACAD_PROXY_ENTITY"))))

;;;--- BEGIN WHILE LOOP TO RUN TYPICAL ACTIONS
(while (< 0 (sslength ss))
  (command "explode" (ssname ss 0))
  (surveycleaner)
  (ssdel (ssname ss 0) ss)
)
(princ)
)

James Cannon

  • Guest
Re: [Newb Help] Filter Objects using dxf code value
« Reply #11 on: May 01, 2009, 05:52:45 PM »
ok, everything is working as planned.

I neglected to put

   (cons 100 "AcDbEntity")
in there before I defined it as mtext.

That meant it didn't create the text at all.

I have not completed the point though, but that'll come Monday, it's 5pm right now, and I have a son to go see.

Thank you all for the help, this is a very successful routine.
I might have to tackle reading the comma delineated .asc file he sends next.  Likely by defining an attributed block in our library and setting the value of the attributes from the comma-delineated info he sends us.  Easy peasy, right?  Hopefully, so!

Thanks all, have a good weekend.

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: [Newb Help] Filter Objects using dxf code value
« Reply #12 on: May 01, 2009, 06:25:35 PM »
I think that revising the function to be like this is more what you are trying to do, Josh. I didn't change the text height (assoc 40) because it is 0.6 now, but you were changing it to 12....big difference. But, it would be simple to add that into the mix, too.
Code: [Select]
(defun SurveyCleaner(/ DESC DESEL ELEEL ELEV NODE NODEL NUMBER NUMEL)

;;;--- ACTIONS TO BE EXECUTED FOR EACH ITEM SELECTED IN THE 'PointFix' routine below
(setq number(ssget "_X" '((62 . 4)(8 . "PT")))) ;;;---selection set of objects color 'cyan' layer PT
(setq elev(ssget "_X" '((62 . 7)(8 . "PT")))) ;;;---selection set of objects color 'white' layer PT
(setq desc(ssget "_X" '((62 . 3)(8 . "PT")))) ;;;---selection set of objects color 'green' layer PT
(setq node(ssget "_X" '((62 . 256)(8 . "PT")))) ;;;---selection set of objects color 'ByLayer' layer PT

(setq numEL (entget (ssname number 0)))
(setq eleEL (entget (ssname elev 0)))
(setq desEL (entget (ssname desc 0)))
(setq nodEL (entget (ssname node 0)))

  (setq numEL (subst (cons 7 "SurveyData") (assoc 7 numEL) numEL)
numEL (subst (cons 8 "SRVY-POINT-No") (assoc 8 numEL) numEL)
numEL (subst (cons 62 256) (assoc 62 numEL) numEL)
)

  (entmod numEL)

  (setq eleEL (subst (cons 7 "SurveyData") (assoc 7 eleEL) eleEL)
eleEL (subst (cons 8 "SRVY-POINT-ELEV") (assoc 8 eleEL) eleEL)
eleEL (subst (cons 62 256) (assoc 62 eleEL) eleEL)
)
  (entmod eleEL)

  (setq desEL (subst (cons 7 "SurveyData") (assoc 7 desEL) desEL)
desEL (subst (cons 8 "SRVY-POINT-DESC") (assoc 8 desEL) desEL)
desEL (subst (cons 62 256) (assoc 62 desEL) desEL)
)

  (entmod desEL)

  (setq nodEL (subst (cons 7 "SurveyData") (assoc 7 nodEL) nodEL)
nodEL (subst (cons 8 "SRVY-POINT-NODE") (assoc 8 nodEL) nodEL)
nodEL (subst (cons 62 256) (assoc 62 nodEL) nodEL)
)

  (entmod nodEL)
  )

HTH, and have a good weekend

mkweaver

  • Bull Frog
  • Posts: 352
Re: [Newb Help] Filter Objects using dxf code value
« Reply #13 on: May 02, 2009, 03:01:59 AM »
heh, I admit, I couldn't get the VLIDE to work for me... 'step into' is greyed out and I have no idea how to use this thing, tbh.

It just shot out
Code: [Select]
Command: ; error: bad DXF group: (10)

In the vlide, go to the Debug pull down menu and check "Break On Error".  This will stop the running code when it errors, allowing you to check/adjust variable values.

Now run your code.  If/when it breaks, go to the View pulldown and pick "Error Trace".  In the resulting window you will see the last half dozen or so calls.  When you see something that doesn't look right, select it and right click, then "Call Point Source" or "Source Position".

This approach will vastly ease troubleshooting.

Mike

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: [Newb Help] Filter Objects using dxf code value
« Reply #14 on: May 03, 2009, 08:25:17 AM »
You could condense the layer and colour changing parts of your code to a local function with arguments, perhaps like this:

Code: [Select]
[color=RED]([/color][color=BLUE]defun[/color] SurveyCleaner  [color=RED]([/color]col newlay [color=BLUE]/[/color] ss eLst[color=RED])[/color]

  [color=RED]([/color][color=BLUE]if[/color] [color=RED]([/color][color=BLUE]setq[/color] ss [color=RED]([/color][color=BLUE]ssget[/color] [color=#ff00ff]"_X"[/color] [color=RED]([/color][color=BLUE]list[/color] [color=RED]([/color][color=BLUE]cons[/color] [color=#009900]62[/color] col[color=RED])[/color] [color=DARKRED]'[/color][color=RED]([/color][color=#009900]8[/color] . [color=#ff00ff]"PT"[/color][color=RED])[/color][color=RED])[/color][color=RED])[/color][color=RED])[/color]
    [color=RED]([/color][color=BLUE]foreach[/color] eLst  [color=RED]([/color][color=BLUE]mapcar[/color] [color=DARKRED]'[/color][color=BLUE]entget[/color] [color=RED]([/color][color=BLUE]mapcar[/color] [color=DARKRED]'[/color][color=BLUE]cadr[/color] [color=RED]([/color][color=BLUE]ssnamex[/color] ss[color=RED])[/color][color=RED])[/color][color=RED])[/color]
      [color=RED]([/color][color=BLUE]setq[/color] eLst [color=RED]([/color][color=BLUE]subst[/color] [color=RED]([/color][color=BLUE]cons[/color] [color=#009900]7[/color] [color=#ff00ff]"SurveyData"[/color][color=RED])[/color] [color=RED]([/color][color=BLUE]assoc[/color] [color=#009900]7[/color] eLst[color=RED])[/color] eLst[color=RED])[/color]
            eLst [color=RED]([/color][color=BLUE]subst[/color] [color=RED]([/color][color=BLUE]cons[/color] [color=#009900]8[/color] newlay[color=RED])[/color] [color=RED]([/color][color=BLUE]assoc[/color] [color=#009900]8[/color] eLst[color=RED])[/color] eLst[color=RED])[/color]
            eLst [color=RED]([/color][color=BLUE]subst[/color] [color=RED]([/color][color=BLUE]cons[/color] [color=#009900]62[/color] [color=#009900]256[/color][color=RED])[/color] [color=RED]([/color][color=BLUE]assoc[/color] [color=#009900]62[/color] eLst[color=RED])[/color] eLst[color=RED])[/color][color=RED])[/color]
      [color=RED]([/color][color=BLUE]entmod[/color] eLst[color=RED])[/color][color=RED])[/color]
    [color=RED]([/color][color=BLUE]princ[/color] [color=#ff00ff]"\n<!> Nothing Found <!>"[/color][color=RED])[/color][color=RED])[/color]

  [color=RED]([/color][color=BLUE]princ[/color][color=RED])[/color][color=RED])[/color]

  [color=#990099];  Example:[/color]

[color=RED]([/color][color=BLUE]mapcar[/color] [color=DARKRED]'[/color]SurveyCleaner
        [color=DARKRED]'[/color][color=RED]([/color][color=#009900]4[/color] [color=#009900]7[/color] [color=#009900]3[/color] [color=#009900]256[/color][color=RED])[/color]
        [color=DARKRED]'[/color][color=RED]([/color][color=#ff00ff]"SRVY-POINT-No"[/color]
          [color=#ff00ff]"SRVY-POINT-ELEV"[/color]
          [color=#ff00ff]"SRVY-POINT-DESC"[/color]
          [color=#ff00ff]"SRVY-POINT-NODE"[/color][color=RED])[/color][color=RED])[/color]