Hatch Control: How to change the .pat file?

Started by roy_043, August 28, 2015, 02:04:44 PM

Previous topic - Next topic

roy_043

While playing with @AllSamples.lsp I noticed that the Hatch Control always uses the definitions from default.pat (I am using BricsCAD) irrespective of the measurement setting. It seems there is no way to change this or am I missing something?

roy_043

Actually the Hatch Control is aware of the measurement setting. It is used to determine the pixel to drawing unit ratio.

In a metric drawing 1 pixel equals 1 drawing unit.
In an imperial drawing 25.4 pixels equal 1 drawing unit.

Displaying imperial hatch definitions at a given scale in a metric drawing results in a much denser preview in the Hatch Control.

roy_043

FWIW: My suggestion for (c:Hatches/Hatch#OnInitialize):
Code (autolisp) Select
(defun c:Hatches/Hatch#OnInitialize (/ scale idx)
  (setq scale (rtos (dcl-Control-GetHatchScale Hatches/Hatch/Hatch1) 2 1))
  (setq idx (dcl-ComboBox-FindStringExact Hatches/Hatch/ComboBox2 scale))
  (if (< idx 0)
    (progn
      (setq idx 0)
      (setq scale (dcl-ComboBox-GetLBText Hatches/Hatch/ComboBox2 idx))
      (dcl-Control-SetHatchScale Hatches/Hatch/Hatch1 (atof scale))
      (dcl-Control-SetHatchScale Hatches/Hatch/Hatch2 (atof scale))
    )
  )
  (dcl-ComboBox-SetCurSel Hatches/Hatch/ComboBox2 idx)
)

owenwengerd

Thanks for the feedback!

It's a good idea to change the derivation of scale to use (rtos (...) 2 1) since the scale combo is hardcoded to use decimal format, but I'm curious what is gained by setting hatch scale when the current scale is not found in the combo. Under what conditions would that occur?
Owen Wengerd (Outside The Box) / ManuSoft

roy_043

Quote from: owenwengerd on September 02, 2015, 09:57:43 AM
Under what conditions would that occur?
The original code assumes that the scale of the Hatch Control can be missing from ComboBox2. In that case ComboBox2 will display the first available scale in the list instead of the actual scale of the Hatch Control. But the Hatch Controls are not updated accordingly. I find this inconsistent. But of course all this is academic in a way. The programmer should ensure that the Hatch Controls have the same scale which should be present in the scale list.

Original code:
Code (autolisp) Select
(defun c:Hatches/Hatch#OnInitialize (/ scale idx)
  (setq scale (rtos (dcl-Control-GetHatchScale Hatches/Hatch/Hatch1) 2 0))
  (setq idx (dcl-ComboBox-FindString Hatches/Hatch/ComboBox2 scale))
  (if (< idx 0) (setq idx 0))
  (dcl-ComboBox-SetCurSel Hatches/Hatch/ComboBox2 idx)
)


owenwengerd

In testing, I found that there is a real bug in that the selected hatch pattern is not remembered between invocations of the sample. Your change doesn't help, because it fails when the selected scale was 10 (rtos returns "10.0", which isn't found in the list). So I changed it like this, which I think is simpler and more consistent:

Code (autolisp) Select

(defun c:Hatches/Hatch#OnInitialize (/ scale idx)
(setq idx (dcl-ComboBox-GetCurSel Hatches/Hatch/ComboBox2))
(if (< idx 0)
(progn
(setq idx 0)
(dcl-ComboBox-SetCurSel Hatches/Hatch/ComboBox2 0)
)
)
(setq scale (dcl-ComboBox-GetLBText Hatches/Hatch/ComboBox2 idx))
(c:Hatches/Hatch/ComboBox2#OnSelChanged nil scale)
)
Owen Wengerd (Outside The Box) / ManuSoft

roy_043

I agree that this is the most elegant way to both solve the inconsistent scale issue and display the selected pattern when the dialog is initialized. And you are right, my code doesn't work with the current odcl scale list which is "5.0|7.5|10" instead of "5.0|7.5|10.0".

But I have caused us to go off on a tangent. My reason for starting this topic is:
Quote from: roy_043 on August 28, 2015, 02:04:44 PM
While playing with @AllSamples.lsp I noticed that the Hatch Control always uses the definitions from default.pat (I am using BricsCAD) irrespective of the measurement setting. It seems there is no way to change this or am I missing something?
If MEASUREMENT=1 the 'iso' .pat file should be used I think. Or there should be a way for the programmer to specify the .pat file.

owenwengerd

Quote from: roy_043 on September 03, 2015, 01:49:33 AM
If MEASUREMENT=1 the 'iso' .pat file should be used I think. Or there should be a way for the programmer to specify the .pat file.

The current solution is to adjust the pattern scale based on the MEASUREMENT setting of the current document. Unfortunately, using the MEASUREMENT setting from the current document leaves a mysterious link from the control to settings in a database whose document happened to be current at the time the control's hatch pattern was last updated.

I will go ahead and change the code to base the control's MEASUREMENT setting on the current document's MEASUREMENT. This doesn't solve the linkage problem, but it should cause the control to use the same .pat file as the current document.
Owen Wengerd (Outside The Box) / ManuSoft