Scripting a hatch - 'New background color'

Scripting a hatch - 'New background color'

Brendan_J_Mallon
Contributor Contributor
599 Views
4 Replies
Message 1 of 5

Scripting a hatch - 'New background color'

Brendan_J_Mallon
Contributor
Contributor

More of an observation about a behavioural change than anything else.  I've applied a workaround for it.  See below.

 

The problem

I've got an application generating a script that includes hatching of the last object the script created:

-hatch
p
s
t
80
co
252
s
l

 

When it gets to setting the colour in a new DWG it's asking for a 'New background color'.

Command: -hatch
Current hatch pattern: _SOLID
Specify internal point or [Properties/Select objects/draW boundary/remove Boundaries/Advanced/DRaw order/Origin/ANnotative/hatch COlor/LAyer/Transparency]: p
Enter a pattern name or [?/Solid/User defined/Gradient] <Solid>: s
Current hatch pattern: SOLID
Specify internal point or [Properties/Select objects/draW boundary/remove Boundaries/Advanced/DRaw order/Origin/ANnotative/hatch COlor/LAyer/Transparency]: t
Specify transparency value (0-90) or [. (for use current)] <use current>: 80
Current hatch pattern: SOLID
Specify internal point or [Properties/Select objects/draW boundary/remove Boundaries/Advanced/DRaw order/Origin/ANnotative/hatch COlor/LAyer/Transparency]: co
New color [Truecolor/COlorbook/. (for use current)] <use current>: 252
New background color [Truecolor/COlorbook/. (for none)] <None>: s
A color number or standard color name is required.
New background color [Truecolor/COlorbook/. (for none)] <None>:
Current hatch pattern: SOLID
Specify internal point or [Properties/Select objects/draW boundary/remove Boundaries/Advanced/DRaw order/Origin/ANnotative/hatch COlor/LAyer/Transparency]:
Command:

 

The script gets stopped here and AutoCAD blinks at me until I've given it an answer.

 

The next time the script is run, it runs cleanly and will continue to run cleanly in the same drawing.

 

It's not template based, as I've tried with the basic acad.dwt file supplied with AutoCAD as well as our own template.  The behaviour is the same.

 

I've had a look at the HPBACKGROUNDCOLOR system variable, but even setting that to something before triggering the script sees it asking for a 'New background color'.  I can see that it has been set (to green (3) in the sample below), but it still triggers the pause for input.

COlor/LAyer/Transparency]: co
New color [Truecolor/COlorbook/. (for use current)] <use current>: 252
New background color [Truecolor/COlorbook/. (for none)] ❤️ (green)>: s
A color number or standard color name is required.
New background color [Truecolor/COlorbook/. (for none)] ❤️ (green)>:

 

I can't easily see another variable that affects the behaviour.

 

To reiterate, it only occurs on the first run in a new drawing and only when scripted.  I cannot trigger it by attempting to run -hatch in the command window.  When it has had its response once, it's fine in that drawing forever.

 

My kludged 'fix'

I found that if I set HPCOLOR before hitting the -hatch part of the script and removed the 'co' component, I could avoid the issue.

HPCOLOR
252
-hatch
p
s
t
80
s
l

 

Clunky but it functions.

0 Likes
600 Views
4 Replies
Replies (4)
Message 2 of 5

Sea-Haven
Mentor
Mentor

You have what looks like a S not a number.

 

0 Likes
Message 3 of 5

Brendan_J_Mallon
Contributor
Contributor

Thanks for the reply.

 

The sequence in the script is correct.  To expand the letters:

-HATCH

Properties

Solid

Transparency

80

COlor

252

Select objects

Last

<blank line to complete selection>

 

The "New background colour..." request only appears in a new drawing, only when running a script and has only come to my attention since we moved to 2022.  It wasn't a problem in 2020.

 

I've got a workaround.  My post was more to document the behaviour in case someone understood the change and whether there was a less clunky 'fix'.  Yes, it's an effective fix.  It just feels clunky.

0 Likes
Message 4 of 5

pendean
Community Legend
Community Legend

@Brendan_J_Mallon wrote:

...only when running a script and has only come to my attention since we moved to 2022.  It wasn't a problem in 2020....


Don't know about 2020 nor 2022, but your script as written in your first post

pendean_0-1715206420670.png

works just fine in plain AutoCAD2023-24-25 here in new and "existing" DWG files in quick tests of each here for me.

pendean_1-1715206483962.png

pendean_2-1715206535249.png

 

So... are you 100% positive that is truly a fail for all possible sessions of 2022, and you personally tested it? If yes, consider upgrading, it's no longer an issue.

0 Likes
Message 5 of 5

Brendan_J_Mallon
Contributor
Contributor

Thanks for the reply.  I'll keep that in mind.

 

As I mentioned, I have applied a workaround, so it's not desperate.

0 Likes