bubble(int numSides) { ObjectId idWO = ObjectId.Null; //wipeout ObjectId idSM = ObjectId.Null; //symbol ObjectId idTX = ObjectId.Null; //text ObjectId idLDR = ObjectId.Null; //leader Object osMode = SnapMode.getOSnap(); SnapMode.setOSnap(0); double angleView = -(double)Application.GetSystemVariable("VIEWTWIST"); Point3d pnt3d = Pub.pnt3dO; Point3d pnt3dEnd = Pub.pnt3dO; Handle hTarget = "0000".stringToHandle(); string layerTarget = ""; ObjectIdCollection idsLDR = new ObjectIdCollection(); FullSubentityPath path = new FullSubentityPath(); List <FullSubentityPath> paths = new List <FullSubentityPath>(); int scale = Misc.getCurrAnnoScale(); bool canLdr = false; string result = bubTxt; try { do { Entity ent = Ldr.getFirstLdrPoint(out pnt3d, out canLdr, out hTarget, out layerTarget, out path); if (ent == null) { break; } Color color = Misc.getColorByLayer(); idLDR = JigSplineLeader_BB.jigSplineLeader(pnt3d, 0.09, "BUBBLE", color); if (idLDR == ObjectId.Null) { break; } paths.Add(path); pnt3dEnd = idLDR.getLastVertex(); Ldr.setLdrXData(pnt3dEnd, idLDR, idSM); idsLDR.Add(idLDR); bool cancel = false; if (idsLDR.Count == 1) { if (numSides == 0) { cancel = UserInput.getUserInput(result, "\nEnter Callout Number: ", out result); if (cancel || result == string.Empty) { return; } bubTxt = result; idTX = Txt.addMText(result, pnt3dEnd, angleView, 0.8, 0.09, AttachmentPoint.MiddleCenter, "Annotative", "BUBBLE", color, Pub.JUSTIFYCENTER); } else { cancel = UserInput.getUserInput(result, "\nEnter Callout Number", out result); if (cancel || result == string.Empty) { return; } bubTxt = result; idSM = Draw.addSymbolAndWipeout(pnt3dEnd, angleView, out idWO, Pub.radius, numSides, true); idSM.moveToTop(); idSM.moveBelow(new ObjectIdCollection { idWO }); idTX = Txt.addMText(result, pnt3dEnd, angleView, 0.0, 0.09, AttachmentPoint.MiddleCenter, "Annotative", "BUBBLE", color, Pub.JUSTIFYCENTER); } } }while (!canLdr); } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " Draw2.cs: line: 91"); } finally { Application.SetSystemVariable("OSMODE", osMode); xRef.unHighlightNestedEntity(paths); } if (idTX.IsValid) { addXData(idSM, scale, idTX, idsLDR, idWO, numSides, hTarget, layerTarget); } }
updateDesignCallout(CogoPoint cogoPnt, string strApp) { ResultBuffer RB = null; MText mText = null; string[] strLines; string[] strFieldsTop; string[] strFieldsBot; string strCalloutX = ""; string strElev = cogoPnt.Location.Z.ToString("#,###.00"); try { using (Transaction tr = BaseObjs.startTransactionDb()) { RB = cogoPnt.GetXDataForApplication(strApp); string strCallout0 = ""; foreach (TypedValue TV in RB) { if (TV.TypeCode.ToString() == "1005") { string strHandle = TV.Value.ToString(); ObjectId objID = Misc.getObjectIdFromHandle(strHandle); Autodesk.AutoCAD.DatabaseServices.DBObject dbObj = tr.GetObject(objID, OpenMode.ForRead); mText = (MText)dbObj; strCallout0 = mText.Contents; if (strApp == "FL") { strLines = Txt.splitLines(strCallout0); strCalloutX = string.Format("{0}\\P{1}", strElev, strLines[1]); } if (strApp == "FF") { strLines = Txt.splitLines(strCallout0); strFieldsTop = Txt.splitFields(strLines[0], ' '); strFieldsBot = Txt.splitFields(strLines[1], ' '); } if (strApp == "G") { strLines = Txt.splitLines(strCallout0); strFieldsTop = Txt.splitFields(strLines[0], ' '); strFieldsBot = Txt.splitFields(strLines[1], ' '); } Events.deactivateMText("*", mText); mText.UpgradeOpen(); mText.Contents = strCalloutX; mText.DowngradeOpen(); Events.activateMText("*", mText); } } RB = mText.GetXDataForApplication(strApp); foreach (TypedValue TV in RB) { if (TV.TypeCode.ToString() == "1005") { string strHandle = TV.Value.ToString(); ObjectId objID = Misc.getObjectIdFromHandle(strHandle); Autodesk.AutoCAD.DatabaseServices.DBObject dbObj = tr.GetObject(objID, OpenMode.ForRead); Leader LDR = (Leader)dbObj; Events.deactivateLdr("*", LDR); LDR.UpgradeOpen(); LDR.SetVertexAt(0, new Point3d(cogoPnt.Location.X, cogoPnt.Location.Y, 0.0)); LDR.DowngradeOpen(); Events.activateLdr("*", LDR); } } tr.Commit(); } //end using tr } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " Mod.cs: line: 1004"); } } //end updateDesignCallout
editExistCalloutsByDatumAdj(SelectionSet SS, double dblAdj) { BlockReference BR = null; string strElev = string.Empty; double dblElev = 0.0; try { using (Transaction tr = BaseObjs.startTransactionDb()) { ObjectId[] objIDs = SS.GetObjectIds(); foreach (ObjectId objID in objIDs) { BR = (BlockReference)tr.GetObject(objID, OpenMode.ForWrite); if (BR != null) { AttributeCollection AC = BR.AttributeCollection; foreach (ObjectId arID in AC) { AttributeReference AR = (AttributeReference)tr.GetObject(arID, OpenMode.ForWrite); string strAttVal = AR.TextString.ToString(); if (strAttVal != string.Empty) { if (strAttVal.StartsWith("(")) { if (strAttVal.Contains(" ") == true) { string[] strFields = Txt.splitFields(strAttVal, ' '); if (strFields[0] != string.Empty) { string strVal = strFields[0]; strElev = strVal.Substring(1, strVal.Length - 1); Boolean boolDbl = double.TryParse(strElev, out dblElev); if (boolDbl == true) { dblElev = dblElev + dblAdj; strElev = dblElev.ToString(); strAttVal = string.Format("({0} {1}", strElev, strFields[1]); AR.TextString = strAttVal; BR.Color = Autodesk.AutoCAD.Colors.Color.FromRgb(255, 200, 200); } } } else { strElev = strAttVal.Substring(1, strAttVal.Length - 2); Boolean boolDbl = double.TryParse(strElev, out dblElev); if (boolDbl == true) { dblElev = dblElev + dblAdj; strElev = dblElev.ToString(); strAttVal = string.Format("({0})", strElev); AR.TextString = strAttVal; BR.Color = Autodesk.AutoCAD.Colors.Color.FromRgb(255, 200, 200); } } } } } } } tr.Commit(); } //end using tr } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " Mod.cs: line: 337"); } }
whip() { bool escape; Entity ent = Select.selectEntity("Select the text: ", out escape); if (escape) { return; } ResultBuffer rb = null; List <string> appList = new List <string>(); if (ent is DBText) { DBText txt = (DBText)ent; rb = txt.GetXDataForApplication(null); if (rb == null) { Txt.rotateText180(ent.ObjectId); } else { TypedValue[] tvs = rb.AsArray(); List <TypedValue[]> tvsList = tvs.parseXData(out appList); if (appList.Contains(apps.lnkGS)) { } } } else if (ent is MText) { MText mTxt = (MText)ent; ObjectId idMTxt = mTxt.ObjectId; rb = mTxt.GetXDataForApplication(null); if (rb == null) { Txt.rotateText180(ent.ObjectId); } else { TypedValue[] tvsMTxt = rb.AsArray(); List <TypedValue[]> tvsList = tvsMTxt.parseXData(out appList); if (appList.Contains(apps.lnkGS)) { rb = mTxt.GetXDataForApplication(apps.lnkGS); TypedValue[] tvs = rb.AsArray(); ObjectId idPnt1 = tvs[9].Value.ToString().stringToHandle().getObjectId(); ObjectId idPnt2 = tvs[10].Value.ToString().stringToHandle().getObjectId(); Point3d pnt3d1, pnt3d2; if (idPnt1.IsValid) { pnt3d1 = idPnt1.getCogoPntCoordinates(); } else { pnt3d1 = Mod.stringCoordinateListToPoint3d(tvsMTxt[11]); } if (idPnt2.IsValid) { pnt3d2 = idPnt2.getCogoPntCoordinates(); } else { pnt3d2 = Mod.stringCoordinateListToPoint3d(tvsMTxt[11]); } double station = double.Parse(tvs[5].Value.ToString()); double offset = double.Parse(tvs[6].Value.ToString()); Point3d pnt3dBase = pnt3d1.traverse(pnt3d1.getDirection(pnt3d2), station); double angle = pnt3dBase.getDirection(mTxt.Location); pnt3dBase = pnt3dBase.traverse(angle, offset); Mod.rotateEnt(ent.ObjectId, pnt3dBase, PI); } else { if (appList.Contains(apps.lnkCO)) { rb = mTxt.GetXDataForApplication(apps.lnkCO); TypedValue[] tvs = rb.AsArray(); ObjectId idldr = tvs.getObjectId(3); Point3d pnt3dBase = idldr.getEndPnt(); idMTxt.flipMTxt(pnt3dBase); ObjectId id = tvs.getObjectId(4); if (id.IsNull) { return; } } else if (appList.Contains(apps.lnkLD)) { } } } } }
updateExistCallouts(SelectionSet SS) { ResultBuffer RB = null; BlockReference BR = null; CogoPoint cogoPnt = null; string strAppName = string.Empty; string strElev = string.Empty; try { using (Transaction tr = BaseObjs.startTransactionDb()) { ObjectId[] objIDs = SS.GetObjectIds(); foreach (ObjectId objID in objIDs) { cogoPnt = (CogoPoint)tr.GetObject(objID, OpenMode.ForRead); strElev = cogoPnt.Location.Z.ToString("#,###.00"); RB = cogoPnt.GetXDataForApplication("lblPnts"); if (RB != null) { strAppName = "lblPnts"; } else { RB = cogoPnt.GetXDataForApplication("lblPntsPT"); strAppName = "lblPntsPT"; } if (RB != null) { try { foreach (TypedValue TV in RB) { if (TV.TypeCode.ToString() == "1005") { try { string strHandle = TV.Value.ToString(); ObjectId brID = Misc.getObjectIdFromHandle(strHandle); Autodesk.AutoCAD.DatabaseServices.DBObject dbObj = tr.GetObject(brID, OpenMode.ForRead); BR = (BlockReference)dbObj; if (BR != null) { AttributeCollection AC = BR.AttributeCollection; foreach (ObjectId arID in AC) { AttributeReference AR = (AttributeReference)tr.GetObject(arID, OpenMode.ForWrite); string strAttVal = AR.TextString.ToString(); if (strAttVal != string.Empty) { string[] strFields = Txt.splitFields(strAttVal, ' '); if (strFields[0] != string.Empty) { string strVal = strFields[0]; if (strVal.StartsWith("(")) { string strChr = strVal[1].ToString(); int num; Boolean isNum = strChr.isInteger(out num); if (isNum == true) { strAttVal = string.Format("({0} {1}", strElev, strFields[1]); AR.TextString = strAttVal; } } } } } } } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " Mod.cs: line: 1091"); } } } } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " Mod.cs: line: 1098"); } } } tr.Commit(); } //end using tr } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " Mod.cs: line: 1108"); } } //end updateDesignCallout
addLdrText(string nameCmd, string nameApp, ObjectId idLdr, List <ObjectId> idsCgPnts, string top = "", string bot = "", string bot2 = "", double deltaZ = 0.0, double xFactor = 0.8, bool useBackgroundFill = false, List <Point3d> pnts3dX = null) { string resultTop = top.ToUpper(); string resultBot = bot.ToUpper(); string resultBot2 = bot2.ToUpper(); Point3d pnt3dTop = Pub.pnt3dO; Point3d pnt3dBot = Pub.pnt3dO; Point3d pnt3dLdrMid = Pub.pnt3dO; Point3d pnt3dLdrIns = Pub.pnt3dO; //text insertion point on Ldr before offset Point3d pnt3dLdrEnd = Pub.pnt3dO; Point3d pnt3d1 = Pub.pnt3dO; Point3d pnt3d2 = Pub.pnt3dO; ObjectId idTxTop = ObjectId.Null; //text ObjectId idTxBot = ObjectId.Null; ObjectId idTxBot2 = ObjectId.Null; double angle = 0.0; double scale = Misc.getCurrAnnoScale(); double gapTop = 0.09; double gapBot = 0.09; List <Point3d> pnts3dLdr = new List <Point3d>(); int n = 0; //Application.ShowAlertDialog(idLDR.IsErased.ToString() + idLDR.IsEffectivelyErased.ToString() + idLDR.ToString()); PromptStatus ps = PromptStatus.Cancel; if (nameCmd == "cmdFFD") { pnt3d1 = UserInput.getPoint("Pick Insertion Point for Label: ", out ps, osMode: 0); //Line line = LdrText_JigLine.jigLine(pnt3d1); //angle = line.Angle; //line.ObjectId.delete(); angle = (double)Application.GetSystemVariable("VIEWTWIST"); } else { if (idLdr.IsEffectivelyErased || idLdr.IsErased) { return; } pnts3dLdr = idLdr.getCoordinates3dList(); n = pnts3dLdr.Count; angle = pnts3dLdr[n - 2].getDirection(pnts3dLdr[n - 1]); //angle opposite direction arrow is pointing for GS or direction of 2nd segment of leader if 3 points pnt3dLdrEnd = pnts3dLdr[n - 1]; } double angleTx = 0; AttachmentPoint apTop; AttachmentPoint apBot; string justifyTop = string.Empty; string justifyBot = string.Empty; bool left_justify = Base_Tools45.Math.left_Justify(angle); if (left_justify) { apTop = AttachmentPoint.BottomLeft; apBot = AttachmentPoint.TopLeft; angleTx = angle + pi; justifyTop = Pub.JUSTIFYLEFT; justifyBot = Pub.JUSTIFYLEFT; } else { apTop = AttachmentPoint.BottomRight; apBot = AttachmentPoint.TopRight; angleTx = angle; justifyTop = Pub.JUSTIFYRIGHT; justifyBot = Pub.JUSTIFYRIGHT; } if (cmdsGS.Contains(nameCmd)) { // overrides for GS commands apTop = AttachmentPoint.BottomCenter; justifyTop = Pub.JUSTIFYCENTER; } if (nameCmd == "cmdFFD") { apTop = AttachmentPoint.MiddleCenter; justifyTop = Pub.JUSTIFYCENTER; } if (nameCmd == "cmdDEP") { justifyTop = Pub.JUSTIFYCENTER; } if (bot.Length < 4) { justifyBot = Pub.JUSTIFYCENTER; } double widthTop = 0; double widthBot = 0; double station = 0.0; double offset = 0.0; Txt.setAnnoStyle(); Color color = Misc.getColorByLayer(); switch (nameCmd) { case "cmdFFD": string txtTop = string.Format("{0}{1}{2}", resultTop, @"\P", resultBot); idTxTop = Txt.addMText(txtTop, pnt3d1, angleTx, 0.0, 0.50, apTop, "Annotative", "GRADES", color, justifyTop, AnnotativeStates.True, 0.8, true, backgroundFill: useBackgroundFill); station = 0.0; offset = 0.0; return; case "cmdGS3": pnt3dLdrMid = idLdr.getBegPnt().getMidPoint2d(idLdr.getEndPnt()); pnt3dLdrIns = pnt3dLdrMid.traverse(angle, (0.09 * scale / 2.4)); if (left_justify) { pnt3dTop = pnt3dLdrIns.traverse(angle - pi / 2, (gapTop * scale / 5)); } else { pnt3dLdrIns = pnt3dLdrMid.traverse(angle, (0.09 * scale / 2.4)); pnt3dTop = pnt3dLdrIns.traverse(angle + pi / 2, (gapTop * scale / 5)); } idTxTop = Txt.addMText(top, pnt3dTop, angleTx, 0.0, 0.085, apTop, "Annotative", "GRADES", color, justifyTop, AnnotativeStates.True, 0.7, backgroundFill: useBackgroundFill); Geom.getStaOff(idsCgPnts, pnt3dLdrIns, ref station, ref offset); pnts3dLdr = new List <Point3d> { idLdr.getBegPnt(), idLdr.getEndPnt(), pnt3dLdrIns }; break; case "cmdGS": case "cmdGS0": case "cmdGSE": case "cmdGSS": case "cmdGSX": case "cmdSL": case "cmdSS": if (nameCmd == "cmdGSX") { gapTop = 0.01; } else { gapTop = 0.09; } pnt3dLdrMid = idLdr.getBegPnt().getMidPoint2d(idLdr.getEndPnt()); pnt3dLdrIns = pnt3dLdrMid.traverse(angle, (0.09 * scale / 2.4)); if (left_justify) { pnt3dTop = pnt3dLdrIns.traverse(angle - pi / 2, (gapTop * scale / 4)); } else { pnt3dTop = pnt3dLdrIns.traverse(angle + pi / 2, (gapTop * scale / 4)); } idTxTop = Txt.addMText(top, pnt3dTop, angleTx, 0.0, 0.09, apTop, "Annotative", "GRADES", color, justifyTop, backgroundFill: useBackgroundFill); Geom.getStaOff(idsCgPnts, pnt3dLdrIns, ref station, ref offset); pnts3dLdr = new List <Point3d> { idLdr.getBegPnt(), idLdr.getEndPnt(), pnt3dLdrIns //pnt3dM - on ldr opposite text insertion point }; break; default: idTxTop = Txt.addMText(resultTop, pnt3dLdrEnd, angleTx, 0.0, 0.09, apTop, "Annotative", "GRADES", color, justifyTop, backgroundFill: useBackgroundFill); widthTop = idTxTop.getMTextWidth(); if (resultBot != string.Empty) { idTxBot = Txt.addMText(resultBot, pnt3dLdrEnd, angleTx, 0.0, 0.09, apBot, "Annotative", "GRADES", color, justifyBot, backgroundFill: useBackgroundFill); } if (resultBot2 != string.Empty) { pnt3dBot = pnt3dLdrEnd.traverse(angleTx - pi / 2, (.14 * scale)); idTxBot2 = Txt.addMText(resultBot2, pnt3dBot, angleTx, 0.0, 0.09, apBot, "Annotative", "GRADES", color, justifyBot, backgroundFill: useBackgroundFill); } station = 0.0; offset = 0.0; break; } if (resultBot == string.Empty || nameCmd == "cmdFFD") { widthBot = 0; } else { widthBot = idTxBot.getMTextWidth(); } double width = 0; if (widthBot > widthTop) { width = widthBot; } else { width = widthTop; } //Adjust callout leader length if (!cmdsGS.Contains(nameCmd)) { if (nameCmd == "cmdFLX" || nameCmd == "cmdGX") { gapTop = 0.01; gapBot = 0.08; } else { gapTop = 0.09; gapBot = 0.09; } Point3d pnt3dLdrEndAdj = pnts3dLdr[n - 2].traverse(angle, width); //reseting leader endpoint based on text width idLdr.adjLdrEndPnt(pnt3dLdrEndAdj); pnts3dLdr = idLdr.getCoordinates3dList(); if (left_justify) { pnt3dTop = pnt3dLdrEndAdj.traverse(angle - pi / 2, gapTop * scale / 4); pnt3dBot = pnt3dLdrEndAdj.traverse(angle + pi / 2, gapBot * scale / 4); } else { pnt3dTop = pnt3dLdrEndAdj.traverse(angle + pi / 2, gapTop * scale / 4); pnt3dBot = pnt3dLdrEndAdj.traverse(angle - pi / 2, gapBot * scale / 4); } idTxTop.adjMTextXYandAngle(pnt3dTop, angleTx, width); if (idTxBot != ObjectId.Null) { idTxBot.adjMTextXYandAngle(pnt3dBot, angleTx, width); } if (idTxBot2 != ObjectId.Null) { if (left_justify) { pnt3dBot = pnt3dLdrEndAdj.traverse(angle + pi / 2, 0.14 * scale); } else { pnt3dBot = pnt3dLdrEndAdj.traverse(angle - pi / 2, 0.14 * scale); } idTxBot2.adjMTextXYandAngle(pnt3dBot, angleTx, width); } } idLdr.moveToTop(); //Add XData if (nameCmd != "cmdRDR" && nameCmd != "cmdSW") { if (idTxTop.IsValid) { addXDataLnks(nameApp, nameCmd, idLdr, idTxTop, idTxBot, idTxBot2, pnt3dTop, scale, deltaZ, pnts3dLdr, idsCgPnts, station, offset, pnts3dX); } else { return; } //addMTextIdToAppDict(nameApp, idTxTop); } }