How to make Hatch via script?

How to make Hatch via script?

Anonymous
Not applicable
4,157 Views
12 Replies
Message 1 of 13

How to make Hatch via script?

Anonymous
Not applicable

Hi all.

I try to make an hatch with .scr script but i can't standardize it because it depends from zoom.

Is there a way to make hatch without considering zoom?

Attacched the script.

0 Likes
Accepted solutions (1)
4,158 Views
12 Replies
Replies (12)
Message 2 of 13

pendean
Community Legend
Community Legend
Hatches are a fixed size, and are not auto-resized based on your zoom level: and no script in LT going to guess at what scale you need based on how far you are zoomed in your DWG file. YOu will need to create a unique script for various sizes of your hatch pattern

Is that perhaps what you are missing? Or something else?

0 Likes
Message 3 of 13

Anonymous
Not applicable

Thks for reply.

The problem is in the objects selection.

The selection varies according to zoom level so i can't standardize the selection rectangles.

The problem is not in hatch settings but only in the selection that it's necessary to identify the area.

0 Likes
Message 4 of 13

pendean
Community Legend
Community Legend

OK, I think I understand now.

 

Did you write this script? explain what is it supposed to do, it is incomplete (and does not complete the HATCH command) and seems to select to window areas that are not related to the circles.

 

You might also wish to look and and use HPLAYER command to set your hatch layer, explore using the MAKE and not the NEW option when creating the layers too, plus the TEXT command is incomplete.

 

And if I may ask: any reason this is not just a ready made block you simply INSERT and explode?

 

 

0 Likes
Message 5 of 13

Anonymous
Not applicable

" Did you write this script? explain what is it supposed to do, it is incomplete (and does not complete the HATCH     command) and seems to select to window areas that are not related to the circles. "

 

Because your zoom level is different from the original.

 

"You might also wish to look and and use HPLAYER command to set your hatch layer, explore using the MAKE and not the NEW option when creating the layers too, plus the TEXT command is incomplete."

 

This commands works fine.

 

"And if I may ask: any reason this is not just a ready made block you simply INSERT and explode?"

 

Because this script is inserted in a Java application than i should provide all users with the blocks and it's impossible to manage...

 

 

0 Likes
Message 6 of 13

pendean
Community Legend
Community Legend
Unless your coordinates choices relative instead of absolute, your hatch portion is windowing two very specific areas on screen so zoom level is irrelevant.

Rewrite your script to reflect your intent for relative
@x,y
Or absolute
#x,y
Instead of
x,y

And that way your script is not crippled by individual DWG file settings the user prefers to use.

0 Likes
Message 7 of 13

Anonymous
Not applicable

Hi.

I've tryed both solutions with # and @ but Autocad says that the selection is not valid.

You can find attacched the script with # and Autocad screenshoot.

 

Are there some errors?

0 Likes
Message 8 of 13

cadffm
Consultant
Consultant

1.

Q: How to make Hatch via script?

A: Same way as not-via-Script (but via commandline)

For example: Some autocad object selection-methods or drawing commands are view depend (nothing to do with scripts),

so you make sure that the view is well, do the the same in your script.

 

2.

It is useless to call international commands when the following options are inserted local

Use italian commands+options, or much better: use international commands AND OPTIONS.

 

3.

In your script are situation of point or object selection and you don't handle the snap mode

Add object snap inputs to your script or manage the osnapcoord value.

 

4.

back to your problem: We can not see your problem in detail without your file (you didn't start with a blank file, right?)

Please upload a sample file, because we don't know about your rectangles.

Upload 1 file "before" and one hand modified file "after", so we can see exactly what you try to do.

General: You know where the rectangles are, so you can ZOOM to the point of selection and

also to zoom out to the bounding area of all needed objects for hatching.

 

5.

Forget the # hint in case of scripts, scripts feeding the commandline, not the dynamic input interface

and in commandline # is useless (or?).

 

_

 

International

Use local or international calls, there is no reason to mix.

 

Command and options, start with an underline, following by the english command/option =>

-TRATTEGGIO | Seleziona oggetti

-hatch | Select objects

 

In your script is just a "S" as option, it will work for english and italien version, but in germany for example not

Schraffur | objekt Auswählen

 

Use _hatch _s will work in "all" language versions.

 

The Point. A POINT ion front of commands force the program to use the native command,

use it to make sure you control the native command.

(3parts can edit the command behind the command call, the point forces acad to use the native command)

 

current: _HATCH s

better:  -TRATTEGGIO s

much better: _HATCH _s

best of: _.HATCH _s (if you want to use the native command)

Sebastian

0 Likes
Message 9 of 13

Anonymous
Not applicable

Hi.

You can find here the dwg file (Test_script_1) that is a blank file and my object is near the origin.

I think the problem is only in the objects selection.

Can you try to exceute my script in the dwg file that i've attacched?

So you can see the problem....

0 Likes
Message 10 of 13

cadffm
Consultant
Consultant

As i wrote: I can see many problems in your script without a run.

 

and what i forgott in my last answer:

 

6.

You don't handle with isle-detect mode, this force the next problem..

 

___

 

First we look at my picture of your file and my 4 lines:

 

190604-1.JPG

These 4 coordinates are from your script.

 

I wouldn't ask this if you upload what i prefered before: ONE BEFORER.dwg and on AFTER.dwg,

in your file we can just see the "after" situation (i guess).

 

You start the hatch command, start the object selection mode and then you fire 4 coordinates to the commandline

and no of them hit an object.. My question is, now: WHY?

 

Check this script, step by step  (the commands, sysvars, what they do and why) / without layer handling

;===

_.OSNAPCOORD 1
_.CIRCLE 1000,1000 350
_.CIRCLE 1000,1000 330
_.ZOOM _w 600,600 1400,1400
_.-HATCH
_p Solid
_s 1000,650 _last


_.ZOOM _p

;====

Sebastian

0 Likes
Message 11 of 13

cadffm
Consultant
Consultant

This is a better version, wherer we do not use a view depend selection method:

;===

_.OSNAPCOORD 1
_.CIRCLE 1000,1000 350
_.SELECT _last

_.CIRCLE 1000,1000 330
_.-HATCH
_p Solid
_s _previous _last

 

;===

Sebastian

0 Likes
Message 12 of 13

Anonymous
Not applicable
Accepted solution

"I wouldn't ask this if you upload what i prefered before: ONE BEFORER.dwg and on AFTER.dwg,

in your file we can just see the "after" situation (i guess)."

 

Yuo can see before.dwg in Test_script_1.dwg and after.dwg just executing the script.

Is this wrong?

Otherwise i don't think i understood the question.

 

"You start the hatch command, start the object selection mode and then you fire 4 coordinates to the commandline

and no of them hit an object.. My question is, now: WHY?"

 

This is the isle-detect mode which i must not exceute.

 

"_.OSNAPCOORD 1
_.CIRCLE 1000,1000 350
_.CIRCLE 1000,1000 330
_.ZOOM _w 600,600 1400,1400
_.-HATCH
_p Solid
_s 1000,650 _last


_.ZOOM _p"

 

I think i found the solution.

Many thanks.

 

Gianluca.

 

0 Likes
Message 13 of 13

steven-g
Mentor
Mentor

Try turning osnaps off before running your script (F3). The problem is that even within a script Autocad will still jump to snap points if the coordinates you are using are close enough to objects on the screen (which will depend on the zoom level). You can globally turn off osnaps at the start of your script with the variable osmode=0. But it is difficult to turn it back on at the end of a script without somehow saving the starting value. A way around this is to use the command modifier "non" before every single coordinate set within your script, for example

_.circle non 1000,1000 350

_.circle non 1000,1000 330

this stops Autocad from automatically snapping to objects

0 Likes