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

MEP 2012 - VB.net - missing step to finalize wire creation

3 REPLIES 3
Reply
Message 1 of 4
jshimkus
687 Views, 3 Replies

MEP 2012 - VB.net - missing step to finalize wire creation

I've been able to use the following code to create a polyline and convert it to a wire.

 

Dim wireseg As Wire = New Wire
wireseg.SetToStandard(mdb)
wireseg.SetDatabaseDefaults(mdb)
Dim wirestyle As String = "Wall Run"
Dim wirestyles As New DictionaryWireStyle(mdb)
wireseg.StyleId = wirestyles.GetAt(wirestyle)
wireseg.SystemId = DictionaryElectricalSystemDefinition.GetStandardDefinition(mdb)

Dim seg As Polyline = New Polyline
seg.AddVertexAt(0, New Point2d(WPSortedArray(wirecnt).wirept.X, WPSortedArray(wirecnt).wirept.Y), 0, 0, 0)
seg.AddVertexAt(1, New Point2d(WPSortedArray(wirecnt + 1).wirept.X, WPSortedArray(wirecnt + 1).wirept.Y), 0, 0, 0)
seg.SetBulgeAt(0, -0.5)

Dim seg1 As CircularArc3d = seg.GetArcSegmentAt(0)
wireseg.SetBaseCurve(seg1, Vector3d.XAxis, 0)
wireseg.UpdateCutPlanesAndNodes()
wireseg.SetDefaultLayer()

btr.AppendEntity(wireseg)
trans.AddNewlyCreatedDBObject(wireseg, True)

When I click on the wire, it shows in the property palette that it is a wire.  It even follows the Wire Cleanup setting for the device it's connected to.

 

The only problem is, I'm missing the tickmark along with the extra grip points for the tickmark.  The wire is also missing the Crossing look when intersecting other wires.  Basically anything on the Annotation tab of the wire style is ignored.

 

I tried using the following code for devices to 'fix' the wire, but it didn't work.

 

Using loadtrans As Transaction = mdb.TransactionManager.StartTransaction()
	Dim addedwire As Wire = DirectCast(loadtrans.GetObject(wireseg.ObjectId, OpenMode.ForWrite), Wire)
	Dim dataRecord As DataRecord = PartManager.GetEngineeringData(addedwire)
	Dim dataField As New DataField(Context.ConnectionPropertyLoad, 1)
	dataField.ValueDouble = 0
	dataRecord.DataFields.Add(dataField)
	PartManager.SetEngineeringData(addedwire, dataRecord)
	addedwire.Dispose()
	loadtrans.Commit()
End Using

 

 

 

3 REPLIES 3
Message 2 of 4
gopinath.taget
in reply to: jshimkus

Hello,

 

Apologies, I am still in consultation with the engineering team on this. I do not have an ETA on this but I am continuing to follow up. I will get back to you as soon as I hear something.

 

Thanks for your patience and apologies for the delay.

 

Best Regards

Gopinath

Message 3 of 4
gopinath.taget
in reply to: jshimkus

Hello,

 

I have a question from the engineering team about your code:

 

*-----------------

Can you please help to check if the style id retrieved by following statements is correct?
 
Dim wirestyle As String = "Wall Run"
Dim wirestyles As New DictionaryWireStyle(mdb)
wireseg.StyleId = wirestyles.GetAt(wirestyle)
 
The annotation properties are based on the wire style. So getting the non-null style id is important.

*-----------------

 

Thanks

Gopinath

 

Message 4 of 4
gopinath.taget
in reply to: jshimkus

Hello,

 

One of my colleagues provided me with an old piece of code to add wire. Hope this helps:

 

using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Windows.Forms;
using System.Drawing;

// AutoCAD MEP Specific
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.GraphicsSystem;
using Autodesk.Aec.DatabaseServices;
using Autodesk.Aec.Building.ApplicationServices;
using Autodesk.Aec.Building.DatabaseServices;
using Autodesk.Aec.Building.Hvac.DatabaseServices;
using Autodesk.Aec.Building.Piping.DatabaseServices;
using Autodesk.Aec.Building.Elec.DatabaseServices;

// create an alias to the AutoCAD Application object
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;
using Entity = Autodesk.AutoCAD.DatabaseServices.Entity;
using ObjectId = Autodesk.AutoCAD.DatabaseServices.ObjectId;
using DictionaryProfileDefinition = Autodesk.Aec.Building.DatabaseServices.DictionaryProfileDefinition;
using ObjectIdCollection = Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection;

//using System.Runtime.InteropServices; // for DllImport


namespace SampleCode.FilpWireTicks
{
class FlipWireTickCommand
{
//[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl, EntryPoint = "acedSSAdd")]
//private static extern int acedSSAdd(long[] ename, long[] sname, long[] result);

//[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl, EntryPoint = "acedSSFree")]
//private static extern int acedSSFree(long[] sname);

//[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl, EntryPoint = "acedSSSetFirst")]
//private static extern int acedSSetFirst(long[] pset, long[] unused);

//[DllImport("acdb17.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl, EntryPoint = "acdbHandEnt")]
//private static extern int acdbHandEnt(string handle, long[] name);

//[DllImport("acdb17.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "?acdbGetAdsName@@YA?AW4ErrorStatus@Acad@@AAY01JVAcDbObjectId@@@Z")]
//private static extern int acdbGetAdsName(long[] name, ObjectId objId);


private static ObjectId[] PromptForObjects()
{
PromptSelectionResult pickFirstResult = Utilities.Editor.SelectImplied();


if (pickFirstResult.Status == PromptStatus.OK)
{
return pickFirstResult.Value.GetObjectIds();
}


PromptSelectionOptions psOptions = new PromptSelectionOptions();
psOptions.MessageForAdding = "\nSelect Wires (other objects will automatically be filtered out): ";

PromptSelectionResult psResult = Utilities.Editor.GetSelection(psOptions);

if (psResult.Status != PromptStatus.OK)
{
return null;
}

return psResult.Value.GetObjectIds();

}

public static void Execute()
{
ObjectId[] oids = PromptForObjects();
if (oids == null)
{
return;
}

FlipWires(oids);

}

private static void FlipWires(ObjectId[] oids)
{
int wireCount = 0;
Database db = AcadApp.DocumentManager.MdiActiveDocument.Database;

using (Transaction trans = db.TransactionManager.StartTransaction())
{
foreach (ObjectId oid in oids)
{
try
{
Wire wire = trans.GetObject(oid, OpenMode.ForWrite) as Wire;
if (wire == null)
{
continue;
}
wireCount++;
int index = 0;
foreach (WireAnnotationTick annTick in wire.AnnotationTicks)
{
annTick.IsFlippedX = !annTick.IsFlippedX;
wire.AnnotationTicks.RemoveAt(index++);
wire.AnnotationTicks.Add(annTick);

}
}
catch
{
}
}
trans.Commit();
}

string msg = String.Format("\n{0} Wire{1} Flipped", wireCount, wireCount == 1 ? "" : "s");
Utilities.Editor.WriteMessage(msg);


}
}
}

 

Best Regards

Gopinath

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