Jump to content

Looking for help with script for hatch in solid colour


Recommended Posts

Hi, I have a script generated in Excel and I am having some difficulty getting the script to hatch a rectangle with solid colour.

 

The following is an excerpt from the script:

 

_layer new Roof colour Truecolor 10,46,18 Roof  

_layer set Roof  

rectangle 90,103100.558672044 14910,103649.948340055  

_hatch Solid 90,103100.558672044 14910,103649.948340055  

line 0,103100.558672044
0,103849.948340055
15000,103849.948340055
15000,103100.558672044

 

The following is the autocad output after running the script:

 

Current layer:  "Roof"
Enter an option [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/TRansparency/MATerial/Plot/Freeze/Thaw/LOck/Unlock/stAte/Description/rEconcile]:

Command: rectangle
Specify first corner point or [Chamfer/Elevation/Fillet/Thickness/Width]: 90,103100.558672044
Specify other corner point or [Area/Dimensions/Rotation]: 14910,103649.948340055
Command:  RECTANGLE

Specify first corner point or [Chamfer/Elevation/Fillet/Thickness/Width]:

Point or option keyword required.

 

With my limited knowledge of scripting I believe the issue is that autocad is looking for a second rectangle to draw which gets me to thinking I have not terminated the rectangle command properly?

 

Appreciate your help, if you need any further info please let me know

 

regards

 

Dave.

Link to comment
Share on other sites

With my limited knowledge of scripting I believe the issue is that autocad is looking for a second rectangle to draw which gets me to thinking I have not terminated the rectangle command properly?

That is certainly what it looks like, Autocad will accept either a line return, a space or the ";" symbol as a way of of imitating the enter key. It is better to use the semi colon, at least you have a better visual clue as to what is going on, just make sure there are no spaces floating at the end of the lines in your code, because pressing enter results in the last used command being repeated in Autocad

Link to comment
Share on other sites

Thanks Steven, I have managed to get it to work by removing the line between rectangle and _hatch however, autocad now reports the following:

 

Command: rectangle
Specify first corner point or [Chamfer/Elevation/Fillet/Thickness/Width]: 90,103100.558672044
Specify other corner point or [Area/Dimensions/Rotation]: 14910,103649.948340055

Command: _hatch
Enter a pattern name or [?/Solid/User defined/Gradient] <ANGLE>: Solid Select objects to define hatch boundary or <direct hatch>,

Select objects: 90,103100.558672044 1 found

Select objects: 14910,103649.948340055 1 found (1 duplicate), 1 total

Select objects:
Command:
HATCH
Select objects to define hatch boundary or <direct hatch>,

Select objects:

Retain polyline boundary? [Yes/No] <N>: line
Yes or No, please.

 

And regardless of whether I select Y or N it asks to Select Start Point which is confusing, should I re enter the co ordinates for the hatch at this point?

 

Kind regards

 

Dave.

Link to comment
Share on other sites

_layer
new
Roof
color
Truecolor
230,230,30
Roof
set
Roof

rectangle
90,103100.558672044
14910,103649.948340055
_hatch
Solid
90,103100.558672044

line
0,103100.558672044
0,103849.948340055
15000,103849.948340055
15000,103100.558672044

Try this, if you look at the command line you should see, that the hatch command is asking you to pick an object, so it only expects one coordinate (one of the corners is fine) otherwise you should tell it that you are going to use a window or fence. I laid out the script a bit differently it's easier to read and follow what is going on(and ignore my earlier comment about the semi colon that's for macro's)

  • Like 1
Link to comment
Share on other sites

Like Steven go a bit more with your excel and work out the midpoint of the rectang PT=(90+14910)/2,(103100+103649)/2

-hatch solid pt

or as you have autocad not LT

-hatch solid '(/(+ 90. 14910.) 2.0) ((+ 10310. 103649) 2.0))

you can run lisp in a script

Link to comment
Share on other sites

Steven, BIGAL,

 

As usual, many many thanks for your replies - I would never have got as far as I have without your help.

 

Following Steven's example, I managed to get it working nicely even with my unconventional approach to layout though, this is driven more by excel than anything else.

 

Once I get through the script and have something complete I will then try to look at learning LISP.

 

Kind regards

 

Dave.

Link to comment
Share on other sites

  • 1 month later...

Hi back again!

 

This time I am having issues with a hatch command for concrete. I have tried numerous variations but not having any luck! My script effectively stops at this point, the rectangle is drawn, however, the hatch is not performed.

 

I have tried using one set of coordinates with no luck

 

Appreciate your advice on where I am going wrong with this please and, if possible, an example of how to write this properly?

 

rectangle 0,36500 6700,36348
_hatch
AR-Conc
1
0
0,36500
6700,36348

 

The above is my script, however, the output in autocad is

 

Command: SCR
SCRIPT
Command: rectangle
Specify first corner point or [Chamfer/Elevation/Fillet/Thickness/Width]: 0,36500
Specify other corner point or [Area/Dimensions/Rotation]: 6700,36348

Command: _hatch

Enter a pattern name or [?/Solid/User defined/Gradient] <ANGLE>: AR-Conc

Specify a scale for the pattern <1.0000>: 1

Specify an angle for the pattern <0>: 0
Select objects to define hatch boundary or <direct hatch>,

Select objects: 0,36500
Specify opposite corner: 6700,36348
[color="red"]0 found[/color]
Select objects:

Retain polyline boundary? [Yes/No] <N>:
Specify start point:
Command:
HATCH
Select objects to define hatch boundary or <direct hatch>,

Select objects:

 

I suspect the item in red is where the problem lies?

 

The strange thing is that I have had this working fine previously and also suspect there might be a system variable that has changed to make it no longer work?

Link to comment
Share on other sites

A script reacts with autocad in the same way as when you use a mouse, and if it can't "see" something on screen it can give problems (bit difficult to describe), but try the following adaption to your script. There are 2 blank lines just before the hatch command

rectangle 0,36500 6700,36348
zoom
ob
l



_hatch
AR-Conc
1
0
0,36500
6700,36348


Link to comment
Share on other sites

Thanks for the example Steven though still having some problems mainly, your example still requires either enter or escape to be pressed to get the hatch drawn, though to get this to happen I had to put a space after 0,36500 and after 6700,36348 under the hatch command to allow one press of escape key - and I note there are three blank lines before the Hatch command I tried reducing to two but this did not work.

 

I'd much prefer no key presses if possible.

 

I should add the following

 

This problem only occurs on a new drawing where there is only one layer being layer 0.

 

I have another drawing that I use for testing my script which contains quite a few layers - 68 layers that were created by the script - and there is no problem running the script on this drawing, the entire script draws perfectly, it's only a problem when running the script on a new blank drawing.

 

I really am at a loss to understand what is going wrong with it?

Link to comment
Share on other sites

Sorry I made that post in the last minute before leaving work and didn't proof read it very well, it should have had 2 blank lines after the zoom command - one to complete the selection and one to complete the zoom command (though now at home only one line is needed - but settings and version differences could account for that).

 

When you are developing scripts the command history often gives a lot of clues (but not always), I tried running the command manually without using the zoom, the rectangle was drawn but not visible on screen, and autocad gave the warning message "Nothing found on screen" when I tried the -hatch command, could it be that on existing drawings you are zoomed out further than on a new file. When using scripts you should turn off osnaps because they can cause scripts not to run as expected due to the zoom level or what is visible on screen, and it would appear as though this also plays a role here.

 

There should also have been 2 blank lines at the end of the script to finish and close the hatch command, again watch the command history as you may only need one.

Link to comment
Share on other sites

A couple more suggestions, try _Hatch S L, sequence is hatch select-object last-drawn its the Rectang ! Re pattern _HPNAME Conc etc _HPANG, _HPSCALE set these before calling the hatch if you want.

 

Another _layer new Roof colour Truecolor 10,46,18 Roof S Roof, no need for 2 lines add the set to the end.

 

Note Steven-g uses the ob object Last drawn in the zoom.

 

rectangle 0,36500 6700,36348
zoom
ob
l



_hatch
AR-Conc
1
0
S
L

Z
P

 

My $0.05 if your using this to draw lots of rectangs 1 after the other then I would go down the lisp path and use excel to write the co-ords for the rectangs to a text file then just read the data file much easier. The other alternative is to take advantage of say GETEXEL.lsp and read the values directly from the excel file letting Autocad do the work. If you have multiples then look at 1 line per rectang in your script use concatenate in excel bit easier to see mistakes.

 

rectangle 0,36500 6700,36348 zoom ob L   _hatch AR-Conc 1 0 S L  Z P
rectangle 0,37500 6700,36500 zoom ob L   _hatch AR-Conc 1 0 S L  Z P

Link to comment
Share on other sites

Thoroughly indebted I am, many, many thanks for your help, it appears it was the zoom level that was the issue - and me misinterpreting your example, turns out the l is a L and not Alt 191 code as it appears when pasting your example into Notepad! - I have went through the whole script in Excel and added the following to every hatch instance and it works perfectly. I have never seen the warning "Nothing found on screen" the closest I've seen is 0 found which confounded me as I knew immediately before it had drawn the rectangle with no error reported, however, "Nothing found on screen" makes sense now that I understand the coordinates need to be brought within the screen area. It was only one blank line needed at the end of the hatch command.

 

rectangle 0,36500 6700,36348
zoom
ob
l

_hatch
AR-Conc
1
0
0,36500

 

I was aware of needing to have osnaps off learned that early on, however, with your reminder I will look at adding the command to turn them off at the beginning of the script.

 

Again, many thanks for your help and explanations Steven really appreciate it.

 

Dave.

Link to comment
Share on other sites

BIGAL, as ever, your help and suggestions are very much appreciated and I will take the time to learn Lisp. My endeavour was to create a calculator for a cold rolled steel building in Excel that the output was to be shoehorned into a C# software program that currently calculates the building incorrectly, this program also has GDi drawing output that is also incorrect so, my Excel calculator was mainly to produce a BOM. The initial drawing output was for the fabrication of C sections to show where holes were required etc this grew to include elevation and frame drawings hence the need for various hatch patterns and fills. Having not much experience with either Autocad or Excel scripting seemed the easier/quicker option to get my head around and without both yours and Steven's help I would never have been able to complete the drawing output, the script runs to just over 9300 lines and for all intents and purposes is complete aside from a few additions and tweaks I'd like to add.

 

I have had a great time learning this as I've went, I've a lot of ideas for creating more building calculators though I may go back to my hot rolled portal calculator and see if I can get it to output fabrication drawings now the pressure is off the cold rolled buildings but undecided whether I do this as a script, Lisp or even try to learn C#.

 

One thing is for certain, I'll no doubt be back with more questions one way or another.

 

And again, really appreciate your help....

 

Dave.

Link to comment
Share on other sites

Osnaps uses "OSMODE" if you set your osnaps to what you want then type OSMODE a number will appear thats the current snap settings, OSMODE 0 is all off, a suggestion is that for most of us that program always set osmode to zero, Autocad can do some funny things particuarly if your creating objects that are not visible.

 

The biggest advantage in going lisp or .net is use of small functions to do repeated tasks rather than constantly repeating lines of code.

 

eg in lisp (rect pt1 pt2) would draw a rectang

Link to comment
Share on other sites

@ ddoc you are welcome, I'm happy to see you got it working.

 

@ BIGAL nice catch on the "l". I am in the habit of using the shortest possible input for scripts, (which is a bad habit) it takes almost no extra time to write out the full command names and options which makes macros and scripts much easier to follow when other people are reading them, but also later on when you revisit your own code to update or adapt them. I do always try to use a ";" instead of a space in macro's and a newline in scripts.

Link to comment
Share on other sites

Yeah Steven-g remembering the space count can be a problem. In word is ok as.you.turn.on.the.display.of.spaces but you have to remember then to save as a text file.

 

 

ddoc 9300 lines is massive you have only hinted at one part of your project it may be a good time to start say with lisp programming. The placement of holes as you hinted is pretty easy and the sort of question that has been asked here multiple times. You may want to look into dynamic blocks just change the values and object is drawn.

 

 

Just me but don't jump into code rather take a step back and figure what is always going to be repeated and could a library function be usefull, 50 questions can be line after line and then put into a fancy dialouge once the code works, I draw little sketches by hand on scrap paper with all the points labelled so I don't forget where I am up to.

 

 

Post a image or dwg there is lots of helpers here as a first step that can suggest the procedures/steps for what you are trying to achieve with or without sample code.

Link to comment
Share on other sites

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