.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Changing Hatch Scale Pattern for Existing Hatch

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
mujibur.rahman
1199 Views, 7 Replies

Changing Hatch Scale Pattern for Existing Hatch

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

7 REPLIES 7
Message 2 of 8
_gile
in reply to: mujibur.rahman

Hi,

 

You should call trx.Commit() and doc.Editor.Regen() outside of the For Each loop.

You should also try to call hatch.EvaluateHatch() after setting the PatternScale.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 8
_gile
in reply to: _gile

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(); } }


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 4 of 8
waseefur.rahman
in reply to: _gile

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

Message 5 of 8
_gile
in reply to: waseefur.rahman

Try calling hatch.EvaluateHatch(false) after SetHatchPattern().



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 6 of 8
waseefur.rahman
in reply to: _gile

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

Message 7 of 8
_gile
in reply to: waseefur.rahman

Sorry but I can only make assumptions. The upper code works with the file you provided on my PC.
The problem seems to come from your colleague's PC. maybe you should try repairing or re-installing AutoCAD.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 8 of 8
waseefur.rahman
in reply to: _gile

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost