Skip to content
On this page

Fill

Solid fill

We can draw solid fill graphics directly through the drawPathToHatch() method provided by the mxcad instance object.

Click drawPathToHatch() to check the properties and methods in detail.

ts
import { MxCpp, McCmColor} from "mxcad"

const mxcad = MxCpp.getCurrentMxCAD()
// Draw a solid triangle to fill.
// Define the start point of a path
mxcad.pathMoveTo(150, 3300);
// The next point on the path
mxcad.pathLineTo(250, 3300);
// The next point on the path
mxcad.pathLineTo(250, 3400);
// The next point on the path
mxcad.pathLineTo(150, 3300);
// Fit the path into a transect
mxcad.drawColor = new McCmColor(255, 0, 0);
mxcad.drawPathToHatch(1);

Pattern fill

We can draw the patternfill pattern by adding a pattern definition using the addPatternDefinition() method provided by the mxcad instance object and setting the newly defined pattern to the value of the line attribute currently drawn by the drawPatternDefinition.

Click on the [addPatternDefinition ()] (https://www.mxdraw3d.com/mxcad_docs/api/classes/2d.McObject.html#addpatterndefinition) View detailed property and method descriptions.

ts
import { MxCpp, McCmColor} from "mxcad"
//angle, x-origin,y-origin, delta-x,delta-y,dash-1,dash-2, …
// "MyHatchPattern1" = Name of the pattern
//45 = angle Indicates the pattern line Angle.
//0 = x-origin is the x-coordinate of the point through which the first fill line passes
//0 = y-origin is the y coordinate of the point through which the first fill line passes
//0 = delta-x is the x-direction offset of the next fill line from the previous one
//0.125 = delta-y is the Y shift of the next fill line from the previous one
const mxcad = MxCpp.getCurrentMxCAD()
mxcad.addPatternDefinition("MyHatchPattern1", "((45, 0,0, 0,0.125))");
mxcad.drawPatternDefinition = "MyHatchPattern1";
// Define the start point of a path
mxcad.pathMoveToEx(600, 3300, 0, 0, 0.3);
// The next point on the path
mxcad.pathLineTo(700, 3300);
// The next point on the path
mxcad.pathLineTo(700, 3400);
// The next point on the path
mxcad.pathLineTo(600, 3300);
// Turn the path into a fill,80, is the scale of the fill pattern.
mxcad.drawPathToHatch(100);

Select point fill

We can use the MxCADUtilityClass class to realize the point-filling function combined with interactive drawing, which provides a series of graph-related tool methods. The builderHatchFromPoint() method provides a point coordinate to fill the corresponding position entity's fill object McDbHatch, if the fill object is successfully drawn, return the fill object, if it is not successfully drawn, return null.

In addition, mxcad provides a series of methods and properties to set the fill object McDbHatch, you can customize the fill graph style according to your needs.

tap MxCADUtilityClass(), McDbHatch() view detailed properties and methods.

ts
import { McGePoint3d, MxCADUiPrPoint, MxCADUtility, MxCpp } from "mxcad";

const getPoint = new MxCADUiPrPoint();
console.log("\n specifies a point inside the fill area :");
getPoint.disableAllTrace(true);
getPoint.setDisableOsnap(true);
let pt = (await getPoint.go()) as McGePoint3d;
if (! pt) return;

let hatch = MxCADUtility.builderHatchFromPoint(pt);
if (! hatch) {
console.log(" Closed region \n not found ")
return;
}
hatch.clearPatternDefinition();
hatch.addPatternDefinition(45, 1, 1, 1, 0.25, [45, 0.17677695, 0, 0, 0.25, 0.125, -0.0625])
hatch.setPattern(McDb.HatchPatternType.kCustomDefined, 'test')
hatch.trueColor = new McCmColor(0, 133, 122)
let mxcad = MxCpp.getCurrentMxCAD();
mxcad.drawEntity(hatch);