I am trying to change the Hatch pattern Scale of an Existing Hatch in my drawing. The Code runs fine but it does not have show any effect on the Hatch
Below is the Coding:
Using trx As Transaction = APPSER.Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction()
Using lock As APPSER.DocumentLock = doc.LockDocument
Dim hatchscale(1) As TypedValue
hatchscale(0) = New TypedValue(DxfCode.Start, "HATCH")
hatchscale(1) = New TypedValue(DxfCode.LayerName, PropertyLayerTable.Rows(i).Item(3).ToString)
Dim hatchsel As New SelectionFilter(hatchscale)
Dim hatchselPsr As PromptSelectionResult = acDocEd.SelectAll(hatchsel)
For Each objid As ObjectId In hatchselPsr.Value.GetObjectIds()
Dim hatch As Hatch = CType(trx.GetObject(objid, OpenMode.ForWrite), Hatch)
hatch.PatternScale = 0.5 / custscale
trx.Commit()
doc.Editor.Regen()
Next
End Using
End Using
Solved! Go to Solution.
Solved by waseefur.rahman. Go to Solution.
Solved by _gile. Go to Solution.
This seems to work.
static double custscale = 1.0;
[CommandMethod("TEST")] public static void TestCmd() { var doc = Application.DocumentManager.MdiActiveDocument; var db = doc.Database; var ed = doc.Editor; var filter = new SelectionFilter(new[] { new TypedValue(0, "HATCH") }); var psr = ed.GetSelection(filter); if (psr.Status != PromptStatus.OK) return; using (var tr = db.TransactionManager.StartTransaction()) { foreach (SelectedObject selectedObject in psr.Value) { var hatch = (Hatch)tr.GetObject(selectedObject.ObjectId, OpenMode.ForWrite); hatch.PatternScale = 0.5 / custscale; hatch.SetHatchPattern(hatch.PatternType, hatch.PatternName); } tr.Commit(); } }
Hi Gile,
the above coding works fine on my PC,
but when I run the same coding in my colleague PC,
value of hatch scale is been updated,
but hatch is not getting changed visually.
I have even tried the various visual updating method ed.regen(),
but still its not getting updated,
even I have reset all setting in my colleague PC to Default,
but still it coding doesn't work, Do I need to change any other settings?
But it work fine on my PC,
can you please advise what might be the problem?
Thanks
Waseef
Hi gile,
it still not worked,
I have attached the file for your Reference.
In the file you can see both Legend Hatch and Room Hatch has same 'Hatch Pattern Scale' value, but there appearance are different.
what was the main problem is same coding it works fine on my PC, whereas in my colleague PC the hatch scale appearance doesn't changes, just the value is updated.
Could you please advice on this?
Thanks
Hi gile,
Thank you for your advice,
Finally @David_W_Koch has Explained it clearly, below is the comments from him.
In your sample file, both hatches use the ANSI31 hatch pattern, but the square hatch in the "Key" area was created when the MEASUREMENT system variable was set to 1 (or was copied from a file in which that was the case), so it used the ACADISO.pat (metric) file version of the definition, while the larger hatch was created with MEASUREMENT set to 0, using the ACAD.pat (imperial) version. The pattern definition in the ACADISO.pat file has numbers that are 25.4 times larger, which accounts for the difference in the pattern scaling.
Thanks everyone for your support..!!