Aller au contenu

CadFrank

Membres
  • Compteur de contenus

    141
  • Inscription

  • Dernière visite

CadFrank's Achievements

Newbie

Newbie (1/14)

0

Réputation sur la communauté

  1. Finalement, j'avais pas a toucher au Field. AttReference.TextString = NewString + AttReference.TextString Sa marche sans défaire mon field... Merci quand meme.
  2. Oui un Field est un champ, dsl mon AutoCAD est en anglais Mon block
  3. Je ne suis pas capable d'y ajouter mon block malheureusement.
  4. Bonjour, J'essai de changer la valeur text d'un attribut qui contient un Field. Par contre, quand ma commande terminer j'obtien un field "####" public class Class { private const string BLOCKNAME = "SOL PL"; private const string TAG_COUNT = "LONG"; private const string TAG_SPACING = "ESPACEMENT"; private const string PREFIX = "%<\\AcObjProp Object(%<\\_ObjId "; private const string SUFFIX = ">%).Parameter(39).lookupString>%"; private string id; //private string textString; private int joistCount; private int spacing; enum DrawingUnit { Imperial, Metrique } [CommandMethod("CS", CommandFlags.UsePickSet)] public void CalculSolives() { Document document = Active.Document; Database database = Active.Database; Editor editor = Active.Editor; PromptSelectionResult psResults = editor.SelectImplied(); if (psResults.Status == PromptStatus.Error) { // Adds options to the Results. PromptSelectionOptions psOptions = new PromptSelectionOptions(); psOptions.MessageForAdding = "\nSélectionner les solives à calculer : "; // this captures the prompt values of the selected object psResults = editor.GetSelection(psOptions); } if (psResults.Status == PromptStatus.OK) { PromptDoubleResult pdResult = editor.GetDistance("Pour la distance utilisé par la/les solive(s). Choisir deux point. :"); double distance = pdResult.Value; using (var transaction = database.TransactionManager.StartTransaction()) { ObjectId[] objIDs = psResults.Value.GetObjectIds(); foreach (ObjectId objID in objIDs) { RXClass attClass = RXClass.GetClass(typeof(BlockReference)); if (objID.ObjectClass.IsDerivedFrom(attClass)) { BlockReference blockReference = transaction.GetObject(objID, OpenMode.ForRead) as BlockReference; AttributeCollection attCollection = blockReference.AttributeCollection; foreach (ObjectId attId in attCollection) { AttributeReference attReference = transaction.GetObject(attId, OpenMode.ForRead) as AttributeReference; if (attReference.Tag == TAG_SPACING) { spacing = getSpacing(attReference); } if (attReference.Tag == TAG_COUNT || attReference.HasFields == true) { ObjectId fieldId = attReference.GetField(); attReference.UpgradeOpen(); id = fieldId.ToString(); id = id.TrimStart('('); id = id.TrimEnd(')'); joistCount = CalculerSolives(spacing, distance); string newString = {:content:}quot;({joistCount}) P.ALU {PREFIX}{id}{SUFFIX}"; attReference.TextString = newString; } } } } transaction.Commit(); editor.Regen(); } } } private int getSpacing(AttributeReference attReference) { int spacing = 0; string textString = attReference.TextString; int index = textString.IndexOf('"'); textString = textString.Substring(2, index - 2); textString = @textString.Trim('"', 'c', '/'); try { spacing = Convert.ToInt32(textString); } catch (Exception) { Active.WriteMessage("Couldn't convert to int..."); } if (CheckDrawingUnit() == DrawingUnit.Metrique) { switch (spacing) { case 8: spacing = 200; break; case 10: spacing = 250; break; case 12: spacing = 300; break; case 16: spacing = 400; break; case 19: spacing = 490; break; } } return spacing; } private DrawingUnit CheckDrawingUnit() { if (Application.GetSystemVariable("DIMLUNIT").Equals(4)) { return DrawingUnit.Imperial; } else { return DrawingUnit.Metrique; } } public int CalculerSolives(int espacement, double distance) { double nombreSolives = distance / espacement; Math.Round(nombreSolives, 0, MidpointRounding.ToEven); return Convert.ToInt32(nombreSolives); } public Field getField(Transaction tr, AttributeReference attReference) { if (attReference.HasFields) { Field field = Active.Database.TransactionManager.GetObject(attReference.GetField(), OpenMode.ForRead) as Field; return field; } return null; } } public static class Active { /// <summary> /// Returns the active Editor object. /// </summary> public static Document Document => Application.DocumentManager.MdiActiveDocument; /// <summary> /// Returns the active Database object. /// </summary> public static Database Database => Document.Database; /// <summary> /// Returns the active Editor object. /// </summary> public static Editor Editor => Document.Editor; /// <summary> /// Sends a string to the command line in the active Editor /// </summary> /// <param name="message">The message to send.</param> public static void WriteMessage(string message) => Editor.WriteMessage(message); /// <summary> /// Sends a string to the command line in the active Editor using String.Format. /// </summary> /// <param name="message">The message containing format specifications.</param> /// <param name="parameter">The variables to substitute into the format string.</param> public static void WriteMessage(string message, params object[] parameter) => Editor.WriteMessage(message, parameter); }
  5. Merci encore de ton aide. Toujours apprécié
  6. je vien de trouver une de tes anciennes discussion et avec elle AutoCAD ouvre. Discussion
  7. Bonjour, J'utilise Autocad 2018 et j'essaie de l'ouvrir avec une fenêtre WPF mais cela ne fonctionne pas. J'ai fais mes recherche et il y a des trucs qui ne marche pas Recherche Voici le code [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("00000016-0000-0000-C000-000000000046")] public interface IMessageFilter { [PreserveSig] int HandleInComingCall(int dwCallType, IntPtr hTaskCaller, int dwTickCount, IntPtr lpInterfaceInfo); [PreserveSig] int RetryRejectedCall(IntPtr hTaskCallee, int dwTickCount, int dwRejectType); [PreserveSig] int MessagePending( IntPtr hTaskCallee, int dwTickCount, int dwPendingType); } /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window, IMessageFilter { [DllImport("ole32.dll")] static extern int CoRegisterMessageFilter(IMessageFilter lpMessageFilter, out IMessageFilter lplpMessageFilter); public MainWindow() { InitializeComponent(); IMessageFilter oldFilter; CoRegisterMessageFilter(this, out oldFilter); } private void btnCreer_Click(object sender, RoutedEventArgs e) { const string productid = "autocad.application.22"; AcadApplication acApp = null; try { acApp = (AcadApplication)Marshal.GetActiveObject(productid); } catch { try { Type acType = Type.GetTypeFromProgID(productid); acApp = (AcadApplication)Activator.CreateInstance(acType, true); } catch { MessageBox.Show("cannot create object of type \"" + productid + "\""); } } if (acApp != null) { acApp.Visible = true; } } #region IMessageFilter Members int IMessageFilter.HandleInComingCall( int dwCallType, IntPtr hTaskCaller, int dwTickCount, IntPtr lpInterfaceInfo ) { return 0; // SERVERCALL_ISHANDLED } int IMessageFilter.RetryRejectedCall( IntPtr hTaskCallee, int dwTickCount, int dwRejectType ) { return 1000; // Retry in a second } int IMessageFilter.MessagePending( IntPtr hTaskCallee, int dwTickCount, int dwPendingType ) { return 1; // PENDINGMSG_WAITNOPROCESS } #endregion } est ce que qu'elle qu'un aurait une solution? Merci,
  8. Finalement, j'ai réussi le faire fonctionner pour un block qui n'est pas dynamic. Merci beaucoup de ton aide précieux. Cordialement.
  9. Je ne sais pas si cela serait possible pour toi de faire une conférence sur HangOuts si cela te convient. P-e que cela m'aiderais a comprendre. On pourrait ce schéduler une date quand tu est disponible.
  10. J'obtiens toujours un erreur fatal. Pourquoi? using (Transaction transaction = Active.Database.TransactionManager.StartTransaction()) { DBDictionary layoutIds = transaction.GetObject(Active.Database.LayoutDictionaryId, OpenMode.ForRead) as DBDictionary; int count = 0; foreach (DBDictionaryEntry entry in layoutIds) { ObjectIdCollection ids = new ObjectIdCollection(); Layout layout = transaction.GetObject(entry.Value, OpenMode.ForRead) as Layout; BlockTableRecord btr = transaction.GetObject(layout.BlockTableRecordId, OpenMode.ForRead) as BlockTableRecord; if (btr.Name != "*Model_Space") { foreach (ObjectId id in btr) { BlockReference br = transaction.GetObject(id, OpenMode.ForRead) as BlockReference; Active.WriteMessage("\n" + br.BlockName); Active.WriteMessage("\n" + br.Name); } } } count++; transaction.Commit(); } Sa fait mal a tete :( Si je le met dans un try c'a me sort "Object reference not set to an instance of an object".
  11. Une autre chose qui me tracasse est quand je débug je ne sais pas quoi regarder. :(
  12. Active est une class appart. public static class Active { /// <summary> /// Returns the active Editor object. /// </summary> public static Document Document { get { return Application.DocumentManager.MdiActiveDocument; } } /// <summary> /// Returns the active Database object. /// </summary> public static Database Database { get { return Document.Database; } } /// <summary> /// Returns the active Editor object. /// </summary> public static Editor Editor { get { return Document.Editor; } } /// <summary> /// Sends a string to the command line in the active Editor /// </summary> /// <param name="message">The message to send.</param> public static void WriteMessage(string message) { Editor.WriteMessage(message); } /// <summary> /// Sends a string to the command line in the active Editor using String.Format. /// </summary> /// <param name="message">The message containing format specifications.</param> /// <param name="parameter">The variables to substitute into the format string.</param> public static void WriteMessage(string message, params object[] parameter) { Editor.WriteMessage(message, parameter); } } using (Transaction transaction = Active.Database.TransactionManager.StartTransaction()) { DBDictionary layoutIds = transaction.GetObject(Active.Database.LayoutDictionaryId, OpenMode.ForRead) as DBDictionary; foreach (DBDictionaryEntry entry in layoutIds) { ObjectIdCollection ids = new ObjectIdCollection(); Layout layout = transaction.GetObject(entry.Value, OpenMode.ForRead) as Layout; // Code. transaction.Commit(); } Est ce que c'est cela tu veux dire par parcourir les Layout avec ACAD_LAYOUT?
  13. Désolé pour le code. Je sais que quelque chose manque dans ma compréhension. Désolé si je ne saisit pas tout en ce moment. Si tu as des références que je peux lire pour m'aider ça serait grandement apprécier. Cordialement,
  14. [CommandMethod("Test")] public static void Test() { var database = Active.Database; using (Transaction transaction = Active.Database.TransactionManager.StartTransaction()) { DBDictionary layoutIds = transaction.GetObject(Active.Database.LayoutDictionaryId, OpenMode.ForRead) as DBDictionary; int count = 0; //int layoutCount = layoutIds.Count - 1; foreach (DBDictionaryEntry entry in layoutIds) { using (Transaction transLayout = Active.Database.TransactionManager.StartTransaction()) { ObjectIdCollection ids = new ObjectIdCollection(); BlockTable blockTable = transLayout.GetObject(database.BlockTableId, OpenMode.ForRead) as BlockTable; Layout layout = transLayout.GetObject(entry.Value, OpenMode.ForRead) as Layout; BlockTableRecord btr = blockTable["CARTOUCHE LU"].GetObject(OpenMode.ForRead) as BlockTableRecord; foreach (ObjectId brId in btr.GetBlockReferenceIds(true, true)) { if (!ids.Contains(brId)) { ids.Add(brId); } } // si le bloc est dynamique on cherche aussi les reférence des blocks anonymes if (btr.IsDynamicBlock) { foreach (ObjectId btrId in btr.GetAnonymousBlockIds()) { var anonymousBtr = (BlockTableRecord)transLayout.GetObject(btrId, OpenMode.ForRead); foreach (ObjectId brId in anonymousBtr.GetBlockReferenceIds(true, true)) { if (!ids.Contains(brId)) { ids.Add(brId); } } } } setTextString(transLayout, ids, "PAGE", count.ToString()); setTextString(transLayout, ids, "#PAGE", (layoutIds.Count - 1).ToString()); transLayout.Commit(); } count++; } transaction.Commit(); } } Bon voici le code que j'ai généré avec ton aide Gile. Par contre, en ce moment il affect que les dernier valeur retenu. Voici le dwg avec le bloc. Si tu as besoin de tester. Je veux que le nombre de page soit en fonction du layout. En ce qui concerne du reste, il reste identique. J'aimerai que des explications et nom le code pour le faire si possible.
  15. Alors si je veux identifier un bloc sur un espace papier. Avec quel élément est-ce que je peux identifier le layout id? J'essaie vraiment de comprend comment leur API fonctionne :S
×
×
  • Créer...

Information importante

Nous avons placé des cookies sur votre appareil pour aider à améliorer ce site. Vous pouvez choisir d’ajuster vos paramètres de cookie, sinon nous supposerons que vous êtes d’accord pour continuer. Politique de confidentialité