Sunday, January 19, 2020

Rectangle Listing Autolisp

Code as below-see

It numbers rectangles and then lists their coordintes in a comma delimited file, ie .csv

;Program written by Bill Le Couteur
;Auckland NZ
;Rev 0 date 29/11/17
;This program selects rectangles and labels them with coordinates,length, width and area

(defun  c:LR()
;(setvar "CMDECHO" 0)
(setq oldsnapmode (getvar "osmode"))
(setvar "osmode" 0)
(command "ucs" "w")
(setq the_count "500"); just a dummy so the while loop keeps going unless user escapes!
(setq count 0)
(setq SerialNo 1)
(setq SerialNos (itoa SerialNo))
(setq the_drg_path (getvar "DWGPREFIX"))
(setq the_file_name (getstring "/nEnter the file name, no prefixes or suffixes: "))
(setq the_text_height (getreal "/nEnter the text height needed: "))

(setq full_file_name (strcat the_drg_path the_file_name ".csv"))

;this makes sure the file is empty if first used!
 (if (not(equal beenthere T))
  (close (open full_file_name  "w"))

;;;;;;;;;;;;;;;;;;WHILE LOOP TO GO PICK RECTANGLES ONE BY ONE;;;;;;;;;;;;

(while (not(equal the_count "1000"))

(prompt "/npick the rectangle")
(setq edata(entget(car(entsel))))                             ;getting the pline's data
(setq ename (cdr(assoc -1 edata)))
(setq the_item (cdr (assoc 0 edata))) ;IF THE USER PICKS A CIRCLE, IT IS A SIGN TO STOP NOW, IE CLOSE THE FILE
;(if (eq "CIRCLE" the_item)
; (progn
; (print "now closing")
; (close fp)
; (exit)
; )progn
;);end if

(print edata)
;you can see the points in the edata list- they are the dotted pairs that start with 10.

(foreach thing edata
        (if(eq (car thing) 10 ); -ie only interested in the points
             (progn;if progn
(print thing)
                (if (eq count 0)(setq the_point0 thing))
(if (eq count 1)(setq the_point1 thing))
(if (eq count 2)(setq the_point2 thing))
(if (eq count 3)(setq the_point3 thing))

(setq count (+ count 1))

         );end progn
    );end if
  );end foreach progn
);end foreach

(setq xvalue1 (nth 1 the_point0))
(setq xvalue1s (rtos xvalue1 2 4))
(setq yvalue1 (nth 2 the_point0))
(setq yvalue1s (rtos yvalue1 2 4))
(setq coordsA (strcat xvalue1s "," yvalue1s))

(setq xvalue2 (nth 1 the_point1))
(setq xvalue2s (rtos xvalue2 2 4))
(setq yvalue2 (nth 2 the_point1))
(setq yvalue2s (rtos yvalue2 2 4))
(setq coordsB (strcat xvalue2s "," yvalue2s))

(setq xvalue3 (nth 1 the_point2))
(setq xvalue3s (rtos xvalue3 2 4))
(setq yvalue3 (nth 2 the_point2))
(setq yvalue3s (rtos yvalue3 2 4))
(setq coordsC (strcat xvalue3s "," yvalue3s))

(setq xvalue4 (nth 1 the_point3))
(setq xvalue4s (rtos xvalue4 2 4))
(setq yvalue4 (nth 2 the_point3))
(setq yvalue4s (rtos yvalue4 2 4))
(setq coordsD (strcat xvalue4s "," yvalue4s))

(setq header_line "Sn,Ax,Ay,Bx,By,Cx,Cy,Dx,Dy,Length,Area")
(setq the_length (- xvalue2 xvalue1))

;;;;;;;;;FOR A NORMAL RECTANGLE;;;;;;;;;;;;;;;;;;;;
(if (> the_length 0)
(setq the_lengths (rtos the_length 2 4))
(setq the_width (- yvalue3 yvalue1))
(setq insert_pointx (+ xvalue1 (/ the_length 2)))
(setq insert_pointy (+ yvalue1 (/ the_width 2)))
(setq insert_point (list insert_pointx insert_pointy))
);end if progn
);end if
;;;;;;;;END OF FOR A NORMAL RECTANGLE;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;FOR A REVERSE RECTANGLE;;;;;;;;;;;;;;;;;;;;
(if (< the_length 0)
(print "hello")
(setq the_length (* the_length -1))
(setq the_lengths (rtos the_length 2 4))
(setq the_width (- yvalue3 yvalue1))
(setq insert_pointx (- xvalue1 (/ the_length 2)))
(setq insert_pointy (+ yvalue1 (/ the_width 2)))
(setq insert_point (list insert_pointx insert_pointy))
);end if progn
);end if
;;;;;;;;END OF FOR A REVERSE RECTANGLE;;;;;;;;;;;;;;;;;;;;

(if (< the_width 0)(setq the_width (* the_width -1)))
(setq the_area (* the_length the_width))
(setq the_areas (rtos the_area))

(setq the_line (strcat SerialNos "," CoordsA ","   CoordsB ","  CoordsC ","  CoordsD "," the_lengths "," the_areas))

(setq the_text_height 300)

(setq fp (open full_file_name "a"))
(if (not(equal beenthere2 T)) (write-line header_line  fp))
(write-line the_line  fp)
(command "text" "j" "m" insert_point the_text_height 0 SerialNos)

(setq SerialNo (+ SerialNo 1))
(setq SerialNos (itoa SerialNo))

(setq beenthere2 T)

(setq count 0)


;;;;;;;;;;;;;;;;;;END OF WHILE LOOP TO GO PICK RECTANGLES ONE BY ONE;;;;;;;;;;;;

(close fp)
 (setq beenthere T)

(command "ucs" "w")
 ;(setvar "CMDECHO" 1)
(setvar "osmode" oldsnapmode)

Tuesday, October 8, 2019

Finally retired?

Maybe.  I have been doing domestic stuff , and in between times entering competitions on Freelancer.

My designs are OK, but there is always some genius out there who usually trumps me at the last minute - and especially when the job needs an artistic sense, it seems I am not in the game.

For things like phone holders and so on I am using a combination of Autocad and Showcase to do my entries, so I cannot blame the tools.

This is the phone holder:

The Mall Kiosk:


A kitchen bin:

As the saying goes: "Don't give up your day job!"

Friday, April 19, 2019

The Old Draftsman

Once Upon a Time, a young engineer went for a walk in the forest.
He came upon an old man, sitting on a tree stump, staring into space.

"Hello," he said, "What are you doing here?"
"Ah," said the old man, "I used to be a draftsman, but then I went mad, so they sent me here."
"Oh? Why did you go mad?" said the young engineer.
"It does not matter now, " the old draftsman replied, "but it was something about drawings that had to be changed,
 and then they wanted me to draw a diagram of the Hazardous Areas in the plant, anyway, I see you are an engineer."

"How did you pick that?"
"Well, it's easy. You have in your hand a bunch of drawings that are printed out with grey lines instead of black."
"Oh that....Well I just get into Autocad and hit the Print button and that's what I get."

A glimmer of hope entered the old draftsman's eye and he said:
"You know, you don't have to do that. It is very simple not to, can I explain how to do it?"
"Noooooo!" wailed the young engineer, "I'm an engineer, I don't have to know that stuff!"

"Please!" entreated the old draftsman, falling to his knees and tugging on the young engineer's sleeve,"you can do it!
 After all, you must be reasonably clever just to do those Engineer's Exams?"

"Well...I suppose so." he answered.

"OK," said the old draftsman "it goes like this: Once upon a time in a land far away and long ago,two elves were designing Autocad."
One turned to the other and said: "How are we going to get thick and thin lines to come out?"
To which the other replied "I know, let's make it one colour for thin lines and another for thick lines."
Then the other said: "How can we make the computer remember which colours are related to which fat or thin lines?"
"That's easy," replied the other, "we can store the values in a separate file,let's call the file extension .ctb,
which stands for colour table....hmm dunno what the b stands for but we have to have 3 letters so there you go."

The old draftsman, sighed, and said:
"Well that's all there is to it: Just hit the print button and in the top right hand corner of the dialog box
there is a selection of ctb files to choose from. I'd suggest you choose the one your draftsman seems to use-
you can spot it right away usually,because it is right at the bottom of the list, called something like 'Freds.ctb'."

The young engineer lived happily ever after.

Thursday, December 13, 2018

Hardware and Software for CAD

I must be nuts! Writing on 3 CAD blogs?

Not such an easy question to answer, mine at the moment is swinging towards using Autocad 3D solids to model houses.   This after a brief foray into the land of Sketchup.  Revit I find wonderful and maddening in equal measure, and will probably end up going down that rabbit hole.

Common to all of these is you have to have a suitable computer to run any of them.

My computer is getting on a bit now (like me) and just lately has started freeze up crashes that are only fixed by disconnecting the power.

So my options are:

1. Replace the hard drive in my existing Z230 with a new SSD for around NZ$150. My wife would certainly see that one as a no-brainer. The Z230 has had it's original K2000 graphics card replaced with a P2000 Quadro, which gives life to the old girl. Using Enscape on it is a delight. but paying for Enscape, not quite so much fun.

2.Buy a new computer. Immediately there is  a choice: Workstation or PC?  A man who started work with me, suggested the following PC:
CPU - Intel i7-8700k                                                                                                         $659.00
Arctic Silver 5 High-Density Silver AS5-3.5G Thermal Compound 3.5          $20.00  
Cooler Master Hyper H411R CPU Cooler with 92mm White LED PWM Fan$44.00
Motherboard - Gigabyte Z390 I AORUS PRO WIFI ITX                                       $401.00
"Hard drive - Samsung 970 Evo M.2 (2280),NVMe SSD R/W(Max)
3,400MB/s/2,300MB/s"                                                                                                 $228.00
Memory - G.SKILL Trident Z Series 32GB (2 x 16GB) DDR4 3200Mhz CL16                $616.00
Power Supply Unit - Cooler Master MWE Gold 650W 80Plus Gold Full
 Modular Power Supply                                                                                                 $162.00
Case - Cooler Master Elite 130 Ultra Compact Mini-ITX USB3.0                     $79.35
"Monitor - Philips BDM4350UC/75 43"" 4K"                                                          $885.00
Mouse - LG Wired                                                                                                           $109.00
Mouse mat                                                                                                                         $26.00
Keyboard - Mechanical (cherry brown) (PB Tech G413
Mechanical Backlit gaming-carbon)                                                                          $148.00
CD/DVD Writer  (PB Tech LG gs40N)                                                                        $54.00
Windows 10 home                                                                                                          $182.00

Apologies for the above blank space- it seems importing stuff from Excel is tricky!

2. The other option is a high spec HP Workstation, which has a supposedly better graphics card in the P4000, namely a HP Z6 G4 3FF57PA

Processor model: Intel Xeon Silver 4116RAM size: 32 GB Graphics processor: Quadro P4000 Type of chassis: MiditowerFlash/SSD
One of these is around NZ$7000, so unless you had huge amounts of highly paid work in front of you, is probably a bit on the high side. 

A friend has pointed me in the direction of some articles, which can be found on the Cadalyst site:

Just to make things even more painful, I am still running with Autocad 2016, which may or may not run 4K nicely, should I go completely mad and get a 43" 4K monitor.  It may run, but with a bit of tweaking.

Friday, March 9, 2018

An Architectural Detail Inserter

Over the years, I have noticed that as a contractor arriving at a new workplace which has other Autocad draftsmen, I would enthusiastically inform them that they could use a lisp routine or button to improve their workflow.

After several rebuffs, I got the message: "We don't want to know."

Sadly, I found this solitary fact about humans: They do not want to know about doing things more efficiently.

It is almost as if they have learnt for themselves some stupid technique, and because they have done this, they own it. That means any other way must be rejected.

I myself am not immune to this process, but if the correct way and reasons for it are placed in front of me, I have on occasion changed my method.

My latest project is a case in point. As an architectural draftsman, one of the more annoying parts of drawing a house is the assembling of the details.  For an ordinary house, this might come to around twenty A3 sheets, with as much as four details per sheet.

Drafting drudgery!  Surely it would be quick an easy to whip up a program to do this?

What were my options?

Using Autolisp was not an option as we are using Autocad LT.  in the past I have used Microsoft Visual Basic to serve as a means to generate an Autocad script, so I decided to go down this rabbit hole.

Three months of weekends and nights slaving over something a real programmer would see as a trivial job, I finished it.

Here it is, in action:

A very simple one form program, all it presents is a list of details on a panel which you choose from.  Once chosen, a preview appears. Pressing another button copies the file name to another panel. Once you have a list, next press another button to generate an Autocad script.

Running the script in Autocad inserts new layouts and viewports.  In model space a set of reference bubbles is found which you then put on your elevation.

My present work has shown no interest, but I retire soon and I may do a similar thing for Revit.  

The ethical consideration of letting a thing like this loose could be concerning.
Instead of spending say one hour inserting details you might spend five minutes.
Less work for draftsmen.  On the other hand, if I don't do it, someone else will.

Which leads me to the strange system of architectural drafting that is the standard at the moment, which is that every drawing office has it's stock of details which it inserts in the set of building consent drawings.

This to me, is nuts!

What is to stop the government from issuing a book of standard details to every builder?  Then all the architect need do is refer to this book in his drawings?

Of course, not all would be covered, but for an ordinary house they would be.

Anyway, check out my video on YouTube at:

Thursday, January 18, 2018

I did it myyyyy way!

Which, sometimes, is not everyone else's way! Recently the boss got me onto a duplex. The source was a drawing already done by an architect in cad, as a PDF file.

Oh goody, I thought, I can try out the 2017 Autocad LT command PDF import.  It seemed to do an excellent job on it, so I scaled it up and away I went, being Mr Efficiency, converting all the layers to our ones.  What I did not take on board, was that the boss, as an owner of the business, wanted things like windows to have a consistent look, and I appreciate that now.

What also proved annoying was the appearance of inaccuracy, namely walls that were not 90.000, but 90.200. Some were, some were not, so everything had to be checked, which makes me think it would have been faster to draw it from scratch.

Then my co-worker mentioned that she found layers named "gf New dim" annoying.  Why not just name them "gf dim"? Well I said that is my doing, because I wanted to have a constant layer set across all jobs, ie residential, commercial and renovation, so I can use my scripts to change colours of layers so I can see what layers I am on.  Currently we only use three colours, so you never quite know what layer an item is.  Needless to say I have a script button that changes all my multicoloured stuff back to good ole red and white!

I am supposedly retiring end of March, and propose to work from home an a contract basis, so it appears I am more wedded to my work than I thought I was.

Saturday, December 2, 2017

Modelling a Cleaner's Trolley

For the last week and a half, I have been laid off work (boss overloaded), so I have been keeping myself busy by entering competitions.  Be warned, these do not pay very much, and if you do not win, you get nothing for all your work.
Still, it seems I have to be cadding along somehow.  One of the competitions was for a motorised version of a cleaner's trolley.  I was quite disappointed when the number of stars I got was 3, and other entries which were just hand sketches got 4 stars. Oh well, this is life! I put quite a lot of consideration into exactly what was going into the trolley, and how it was to be accessed.  The more highly rated did not seem to even consider the items to go inside.

Here is my entry, modelled in Autocad 3D solids, and rendered in Showcase:

Added 19 December 2017, this was the winning entry: