Author Topic: Area reactor  (Read 33930 times)

0 Members and 1 Guest are viewing this topic.

MvdP

  • Guest
Re: Area reactor
« Reply #30 on: June 09, 2006, 02:23:29 AM »
I have tested your code and the difference is that yours is showing the drop downlist.
But it gives an error.I think it seems to be that the variable area-name is not set from the drop downlist.

I checked it by letting it print the two variables on the commandline,but no show.!!!!

Code: [Select]
(defun c:ddla (/ ar1 ar2 tab oba inspoint objarea)
(vl-load-com)

(setq areanamelist(list "RoomA" "RoomB" "RoomC" "RoomD" "RoomE"))


(setq DH (load_dialog "DDlabelarea"))
(new_dialog "DDlabelarea" DH)
(start_list "areanamelist")
(mapcar 'add_list areanamelist)
(end_list)

(action_tile "accept" "(done_dialog 1) (setq area-name (get_tile \"areanamelist\"))")
(action_tile "cancel" "(exit)(exit)")
(setq RET (start_dialog))}

  (setvar "cmdecho" 1)
  (setq fd (getvar "fielddisplay"))
  (if (/= fd 1)(setvar"fielddisplay" 1))

(setq ar1 (entsel "\nSelect Area Boundary: "))
(setq ar2 (car ar1))
(setq tab (vlax-ename->vla-object ar2))
(setq oba (vla-get-objectid tab))


(princ)
;;(setq inspoint (getpoint "\nPick label insertion point:  "))
(princ)
(setq objarea (strcat "%<\\AcObjProp Object(%<\\_ObjId " (rtos oba 2 0) ">%).Area \\f \"%lu2%pr2%ps[, m2]%ds44%ct8[1e-006]\">%"))
(setvar "attdia" 0)
(setvar "attreq" 1)
(setq schaal (rtos(getvar "userr1")))
  (princ objarea)
  (princ area-name)
  ;;(command "-insert" "oppervlakte" "s" schaal inspoint "" area-name objarea )
(setvar "attdia" 1)
(setvar "attreq" 1)
(princ)
)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Area reactor
« Reply #31 on: June 09, 2006, 11:11:15 AM »
Okay, sorry about that.  Here is the one that works.
Code: [Select]
(defun c:ddla (/ ar1 ar2 tab oba inspoint objarea)
(vl-load-com)

(setq areanamelist(list "RoomA" "RoomB" "RoomC" "RoomD" "RoomE"))


(setq DH (load_dialog "DDlabelarea"))
(new_dialog "DDlabelarea" DH)
(start_list "areanamelist")
(mapcar 'add_list areanamelist)
(end_list)

(action_tile "accept" "(setq area-name (get_tile \"areanamelist\"))(done_dialog 1)")
(action_tile "cancel" "(exit)(exit)")
(setq RET (start_dialog))}

  (setvar "cmdecho" 1)
  (setq fd (getvar "fielddisplay"))
  (if (/= fd 1)(setvar"fielddisplay" 1))

(setq ar1 (entsel "\nSelect Area Boundary: "))
(setq ar2 (car ar1))
(setq tab (vlax-ename->vla-object ar2))
(setq oba (vla-get-objectid tab))


(princ)
(setq inspoint (getpoint "\nPick label insertion point:  "))
(princ)
(setq objarea (strcat "%<\\AcObjProp Object(%<\\_ObjId " (rtos oba 2 0) ">%).Area \\f \"%lu2%pr2%ps[, m2]%ds44%ct8[1e-006]\">%"))
(setvar "attdia" 0)
(setvar "attreq" 1)
(setq schaal (rtos(getvar "userr1")))
  (princ objarea)
  (print area-name)
  (command "-insert" "oppervlakte" "s" 1.0 inspoint "" (nth (atoi area-name) areanamelist) objarea )
(setvar "attdia" 1)
(setvar "attreq" 1)
(princ)
)

I don't know where the variable "schaal" is being set, so I took it out to test here.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

MvdP

  • Guest
Re: Area reactor
« Reply #32 on: June 09, 2006, 11:20:46 AM »
Thanks again Tim.Where would i be without you.(and offcourse this the Swamp)


I am not able to test your code right now but i have another question.
When working with fields and adjust the area (polyline) you have to regen to display the new values.Is it somehow possible to show this immediately so without a regen.?

The variable "schaal" is the scale factor.
The routine  inserts the block called "oppervlakte" times the scale.(but this works)
« Last Edit: June 09, 2006, 11:39:50 AM by MvdP »

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Area reactor
« Reply #33 on: June 09, 2006, 01:12:34 PM »
You're welcome.

As far as fields go, I have no idea.  I don't use them, sorry I can't be more help.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

MvdP

  • Guest
Re: Area reactor
« Reply #34 on: June 12, 2006, 03:10:57 AM »
Thanks Tim it worked perfectly.I added a drop down list for rotation and this is working also.

So now i want to go further.How can this be done(if possible).?
After the routine has been inserted the block and adjusted the values how to select in lisp the block and the corresponding polyline so that the two objects can be hatched in a specific pattern(depends of area-name ,i want to add a toogle yes/no option in dcl).
F.i. Room A -D has a user singel hatch pattern with an angle of 45 and the toilet has the same but double hatch pattern.
« Last Edit: June 12, 2006, 10:59:17 AM by MvdP »

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Area reactor
« Reply #35 on: June 12, 2006, 11:18:02 AM »
You will already know the polyline objects name (got it from entsel), and to grab the blocks, just use "entlast" after you insert it.  Then look at the hatch command, and see how you would hatch it, with selecting an object.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

MvdP

  • Guest
Re: Area reactor
« Reply #36 on: June 12, 2006, 11:59:34 AM »
So if i understand it correctly i have to do something like this.
I have to set a variable f.i. hatchobjects


(setq hatchobjects(entlast)) ;;;;;; for selecting the block
after this do this
(command "-bhatch"   hatchobjects - here the hatch settings i want.- )

but where do i put ar1 (polylines name) to combine it with entaslt.
Btw i hope you don't mind me asking so much questions.As stated before i  am no stranger with AutoCAD (started with v 2.6 a thought it was)  but a total newbie with programming.And it is a lot of fun.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Area reactor
« Reply #37 on: June 12, 2006, 12:30:07 PM »
(command "_.bhatch" "_s" ar1 hatchobject "")

This will select the two objects.  Now you will need to set the pattern, and scale.  It's okay to ask questions, as long as you try the answers posted.  We are here to teach/learn, so ask away.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

MvdP

  • Guest
Re: Area reactor
« Reply #38 on: June 13, 2006, 04:40:02 AM »
Off course i am trying all the answers posted ,and i am learning all the time.

So now i got this thing working but not yet the way i want.So let me try to explain how i want it to work.And ask two questions.

Question 1

If i select the area name f.i. "room A'" i want it hatched user defined single  and when i select the area name f.i. toilet i want it to be hatched the same but double.How to do this.

Tried this but no luck.

(if (= hatch-area "J" = area-name "Room A")(command "-bhatch" "s" ar1 hatchobjects "" "p" "u" "45" "150" "n" ""))
(if (= hatch-area "J" = area-name "Toilet" )  (command "-bhatch" "s" ar1 hatchobjects "" "p" "u" "45" "150" "y" ""))


Question 2

I want the selection option to select only a closed polyline, and when i do not select a prompt.
This is what i got so far but again i cant figure out what is wrong with this.

Code: [Select]
(defun do_pick (/ area1)
  (while (setq area1 (entsel "\nSelect polyline: "))
    (if
      (member (cdr (assoc 0 (setq entlst (entget (car area1)))))
              '("LWPOLYLINE" ))
       )
       (prompt "\nError selected object is NOT a LWpolyline.")
    )
  )
  (if (null area1)
    (prompt "\nNothing selected.............................")
  )
)
 

and change this

Code: [Select]
(setq area1 (entsel "\nSelect Area Boundary: "))
(setq area2 (car area1))
(setq tab (vlax-ename->vla-object area2))
(setq oba (vla-get-objectid tab))


into this
Code: [Select]
(do_pick)
(setq area2 (car area1))
(setq tab (vlax-ename->vla-object area2))
(setq oba (vla-get-objectid tab))



« Last Edit: June 13, 2006, 08:09:36 AM by MvdP »

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Area reactor
« Reply #39 on: June 13, 2006, 11:43:47 AM »
Answer 1.
You should use a (cond.... not an (if....  If you have more that two options, then use (cond... it's a general rule I use.  So it would look like
Code: [Select]
(cond
 ((= area-name "RoomA")
  (setq DblHatch "_n")
 )
 ((= area-name "Toilet")
  (setq DblHatch "_y")
 )
)
(command "_.bhatch" "_s" ar1 hatchobjects "" "_p" "_u" "45" "150" DblHatch "")

Answer 2
If you only want to select closed polylines, then you need to check the dxf code 70.  So something like
Code: [Select]
(while (not (setq ss (ssget ":e:s" '((0 . "LWPOLYLINE") (70 . 1))))))
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

MvdP

  • Guest
Re: Area reactor
« Reply #40 on: June 13, 2006, 11:54:46 AM »
A reaction to answer 1.So this is also possible.?


Code: [Select]
(cond
((= area-name "RoomA")
  (setq DblHatch "_n")(setq AngHatch "45")
)
((= area-name "Toilet")
  (setq DblHatch "_y")(setq AngHatch "135")
)
)
(command "_.bhatch" "_s" ar1 hatchobjects "" "_p" "_u" AngHatch "150" DblHatch "")


T.Willey

  • Needs a day job
  • Posts: 5251
Re: Area reactor
« Reply #41 on: June 13, 2006, 12:04:15 PM »
Yup.  That is another good thing about (cond... 's.  With and (if... statement, you can only have one action happen per statement, that is why you need the (progn.... when you want more than one thing to happen, but with (cond... you don't need the (progn....
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

MvdP

  • Guest
Re: Area reactor
« Reply #42 on: June 13, 2006, 12:09:39 PM »
Thanks for the info about the conds ,but I still dont get it where to put this.

Code: [Select]
(while (not (setq ss (ssget ":e:s" '((0 . "LWPOLYLINE") (70 . 1))))))

and where to put the text when nothing is selected, and the text when anything else but a polyline is selected.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Area reactor
« Reply #43 on: June 13, 2006, 12:13:56 PM »
This will only let you select a closed pline.  You will have to escape out of it.  Have you tried it?  After you get past the loop, then you will set ar1 to the only object (or the first object) in the selection set.

(setq ar1 (ssname ss 0))

This will get you the closed polyline that was selected.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

MvdP

  • Guest
Re: Area reactor
« Reply #44 on: June 13, 2006, 12:18:46 PM »
I will try tomorrow.Now i am going to watch tv (WC 2006 in Germany) and have diner.