Skip to content
On this page

Line table

In the DWG database, the line style is stored in the line style sheet McDbLinetypeTable(), and each record in the line style sheet is called the line table record object McDbLinetypeTableRecord(). Each line table record object corresponds to a line style, which is saved with the drawing, and the line style used by different drawings may be different.

We can get the current control by calling 'MxCpp.getCurrentMxCAD()' in mxcad and then call the getDatabase() method of the control instance to get the database instance McDbDatabase(). By calling getLinetypeTable() in this database instance, we get the linear style sheet McDbLinetypeTable().

Click on linear stylesheet McDbLinetypeTable(), linear table record object McDbLinetypeTableRecord(), the database instance McDbDatabase() to check the detailed description attributes and methods.

ts
import { MxCpp} from "mxcad"
// Get the current control
const mxcad = MxCpp.getCurrentMxCAD();
// Get the current line style sheet
const lineTypeTable = mxcad.getDatabase().getLinetypeTable();

Add line lines

We can add a line style directly by calling the addLinetype() method or the addLinetypeEx() method in the mxcad instance object, and then set the drawLinetype property to set the added line style to the current drawn line style.

Click on McObject.addLinetype()McObject.addLinetypeEx() to check the properties and methods in detail.

ts
import { McApp } from "mxcad"

const mxcad = McApp.getCurrentMxCAD()
// Define dashed data,"MyLineType" is the line name," 6,-8" is a unit definition of the dashed line, 6 is the length of the solid line, and -8 is the length of the space.
mxcad.addLinetype("MyLineType", "6,-10");

Mxcad. AddLinetypeEx (" TestMyLine ", '. 5, -. 2, [" HW ", STANDARD, S = 1, R = 0.0, X = 0.1, Y = - 05], -. 2 ', "");
// Design current line type as "MyLineType"
mxcad.drawLinetype = "MyLineType";

Alternatively, we can add a line table record object, McDbLinetypeTable(), to the style sheet by taking the linear style sheet McDbLinetypeTableRecord() in the current database.

ts
import { McCmColor, MxCpp, McDbLinetypeTableRecord, McDb } from "mxcad"

const mxcad = MxCpp.getCurrentMxCAD();
// Get the current line style sheet
let linetypeTable = mxcad.getDatabase().getLinetypeTable();
// Create a linear record object
let newLinetypeRecord = new McDbLinetypeTableRecord();
// Set the number of dashed lines
newLinetypeRecord.numDashes = 2;
// Set the line name
newLinetypeRecord.name = "TestMyLine"
// Add a line line
if (linetypeTable.add(newLinetypeRecord).isValid()) {
console.log("add ok");
}

Traversing all lines

We can get the ids of all linear styles by calling the getAllRecordId() method in the linear style sheet McDbLinetypeTable(), Call again getMcDbLinetypeTableRecord () method returns the linear table record McDbLinetypeTableRecord (), all data linear style.

ts
import { MxCpp } from "mxcad"

// Get the current cad object
let mxcad = MxCpp.getCurrentMxCAD();
// Get the line table
let linetypeTable = mxcad.getDatabase().getLinetypeTable();
// Gets all record object ids in the line table
let aryId = linetypeTable.getAllRecordId();
// Traversal linear record object id
aryId.forEach((id) => {
    let linetypeRec = id.getMcDbLinetypeTableRecord();
    if (linetypeRec === null) return;
    console.log(linetypeRec);
    console.log("linetypeRec.name:" + linetypeRec.name);
});

Delete line lines

After we get the target linear table record object McDbLinetypeTableRecord(), we can call the erase() method of the object instance to delete the object.

ts
import { MxCpp } from "mxcad"
// Get the line table
let linetypeTable = MxCpp.getCurrentMxCAD().getDatabase().getLinetypeTable()
let linetypeId = linetypeTable.get(" Target line style name ")
linetypeId.erase()
// Update the display
mxcad.updateDisplay()

Modify the line type

The basic operation of modifying line line in mxcad is to delete the original line line, re-add the defined line line, and finally set the target object to the new line line. Let the user select a text object on a CAD drawing, and then manipulate the linear style applied to the object as an example:

ts
import { MxCADSelectionSet, MxCADUiPrPoint, MxCADResbuf } from "mxcad"

let mxcad = MxCpp.getCurrentMxCAD();
// Delete the existing "TestMyLine" line from the current diagram and add a new definition line for mxcad.addLinetypeEx.
let linetypeRecord = mxcad.database.getLinetypeTable().get("TestMyLine");
if(! linetypeRecord.isErase()){
linetypeRecord.erase();
}
// Add the line definition TestMyLine
Let lintype = mxcad. AddLinetypeEx (" TestMyLine ", '. 5, -. 2, [" HW ", STANDARD, S = 1, R = 0.0, X = 0.1, Y = - 05], -. 2 ', "");
if(! lintype.isValid() )return;
// Modify the target object line
let getEnt = new MxCADUiPrEntity();
let entId = await getEnt.go();
let ent = entId.getMcDbEntity();
if(!ent) return;
ent.linetypeId = lintype;