The creation of hatches differs from other entities such as blocks, text styles, and callout styles, and the approximate method and procedure are basically the same, only in individual places. To create a Hatch object, first use the class's constructor to create an empty fill object, and then set the properties for the object's type, style, name, fill angle, and bounds. Steps are as follows
1. Create a pattern boundary:
Create a fill boundary with the Create Circle command
Circle Circle = New Circle (); circle. Setdatabasedefaults ();//used to set the circle color, layer, Linetype, plot style, visibility and other properties as the default value circle for the database in which the entity resides. Center = new Point3D (3, 3, 0); circle. Radius = 1;
2. Create Hatch objects:
Hactch Hatch =new Hatch ();
3. Set the properties of the Hatch object:
hacth.patternscale=0.5;
4. Set the fill type and Hatch pattern name:
Hatch. Setdatabasedefaults (); Hatch. Sethatchpattern (hatchpatterntype.predefined, "ANSI31");
Hatchpatterntype Property Description:
hatchpatterntype.predefined
Select from the pattern names defined in the Acad.pat file.
hatchpatterntype.userdefined
Defines the line pattern with the current linetype.
hatchpatterntype.customdefined
Select the pattern name from the PAT instead of the Acad.pat file.
Fill type Description:
ANSI31: For the metal profile line
Other as
5. Set the association:
6. Add fill boundary:
Achatch.appendloop (Hatchlooptypes.outermost, IDS);//ids here for Objectid set
Description: The first boundary added must be an outer boundary, which defines the outermost boundary of the hatch. To add an outer boundary, use the Appendloop method with the Hatchlooptypes.outermost constant of the add ring, and once the outer boundary is defined, you can continue adding additional boundaries. To add an internal boundary, use the Appendloop method with Hatchlooptypes.default constants.
7. Calculate and display the fill:
Hatch. Evaluatehatch (TRUE);
8. Submit Transaction Processing:
Trans.commit ();
Full code:
1 usingAutodesk.AutoCAD.Runtime;2 3 usingAutodesk.AutoCAD.ApplicationServices;4 5 usingAutodesk.AutoCAD.DatabaseServices;6 7 usingAutodesk.AutoCAD.Geometry;8 9 Ten One[Commandmethod ("Addhatch")] A - Public Static voidAddhatch () - the { - - //get the current document and database - +Document Acdoc =Application.DocumentManager.MdiActiveDocument; - +Database Accurdb =acdoc.database; A at - - //Start a transaction - - using(Transaction trans =acCurDb.TransactionManager.StartTransaction ()) - in { - to //open a block table as read-only + - blocktable acblktbl; the *ACBLKTBL =Actrans.getobject (Accurdb.blocktableid, $ Panax NotoginsengOpenmode.forread) asblocktable; - the + A //Open the Model Space block table record in write mode the + Blocktablerecord Acblktblrec; - $Acblktblrec =Actrans.getobject (Acblktbl[blocktablerecord.modelspace], $ -Openmode.forwrite) asBlocktablerecord; - the - Wuyi //creates a circle object as the enclosing boundary of the hatch the -Circle Circle =NewCircle ();//Initialize the Circle class Wu -Circle. Setdatabasedefaults ();//Default Parameters About $Circle. Center =NewPoint3D ();//Center Position - -Circle. Radius =1;//radius of the circle - A + the //Add a new Circle object to the block table record and the transaction - $ acblktblrec.appendentity (circle); the theActrans.addnewlycreateddbobject (Circle,true); the the - in //Add a circle to a ObjectID array the theObjectidcollection Acobjidcoll =Newobjectidcollection (); About the Acobjidcoll.add (Circle. OBJECTID); the the + - //Create a Hatch object and add it to the Block table record the BayiHatch Hatch =NewHatch (); the the acblktblrec.appendentity (hatch); - -Actrans.addnewlycreateddbobject (Hatch,true); the the the the Hatch. Setdatabasedefaults (); - theHatch. Sethatchpattern (hatchpatterntype.predefined,"ANSI31");//ANSI31 for metal profile lines the theHatch. associative =true;94 the Hatch. Appendloop (Hatchlooptypes.outermost, acobjidcoll); the theHatch. Evaluatehatch (true);98 About - 101 //Save the new object to the database102 103 trans.commit ();104 the }106 107}
. NET AutoCAD Two-time Development road (five, populate)