Dimension alignment issue in PDF after exporting to PDF using .NET, C#

Dimension alignment issue in PDF after exporting to PDF using .NET, C#

madhukum339
Participant Participant
276 Views
6 Replies
Message 1 of 7

Dimension alignment issue in PDF after exporting to PDF using .NET, C#

madhukum339
Participant
Participant

Hi, 

 

    I have a C# code of updating the custom made "T" dynamic block properties and after updating the properties Distance1, Distance2, Distance3. I'm exporting to pdf from Model space. But facing issue with the alignment of the dimensions in PDF. Attaching the video for reference, kindly go

through and help me. Thanks in advance. 

 

 


0 Likes
Accepted solutions (1)
277 Views
6 Replies
Replies (6)
Message 2 of 7

BlackBox_
Advisor
Advisor

You didn't post your .NET code, so you're not going to get much help. 

 

From the video, Task.dwg is not saved after MAPDIM, so I'm guessing you're plotting the original file (from filepath), in lieu of the unsaved changes in the active document.  


"How we think determines what we do, and what we do determines what we get."

Sincpac C3D ~ Autodesk Exchange Apps

0 Likes
Message 3 of 7

madhukum339
Participant
Participant

Hi @BlackBox_ ,

 

Attaching the code, kindly go through and let me know, if this helps to answer. Thank you,

 

 

 

0 Likes
Message 4 of 7

BlackBox_
Advisor
Advisor

Thanks; I'm (happy?) sad to report that this code is working on my end. 

 

However, since you only shared a few methods, and not an entire class with the missing dependencies (like taskPath, doc, your custom Block, etc), I had to create my own CommandMethod using Application.GetSystemVariable("DWGPREFIX").ToString() for taskpath, and Application.DocumentManager.MdiActiveDocument for doc.

 

Otherwise, it worked quite well - with such a small test drawing, it was near instant, so I'm curious to test it on my normal (large) C3D drawings. 

 

One thing that stood out from Kean's example here, is that your PublishModelSpaceToPdf() method includes tr.Commit() where Kean does not - that said, both leaving it as-is and commenting it out resulted in a successful plot of the unsaved changes I was making to a polyline & dimensions I used as placeholder for your Block. 

 

Cheers


"How we think determines what we do, and what we do determines what we get."

Sincpac C3D ~ Autodesk Exchange Apps

0 Likes
Message 5 of 7

madhukum339
Participant
Participant

Thanks for your reply @BlackBox_ , have you checked with dimension alignment in pdf after updating dynamic block properties. attaching the rest of the code.

 

I have attached the .dwg and .pdf for reference at the top. 

 

madhukum339_0-1756186529028.png

 

 

0 Likes
Message 6 of 7

norman.yuan
Mentor
Mentor
Accepted solution

@madhukum339 

 

It looks to me, your code is problematic: the class level variable "plot" is initialized as "false", and never changed, thus, the last 2 lines of code in the command method:

if (plot)

  PublishModelSpaceToPdf() 

is never executed.

 

However, your have the save 2 lines of code in the ProcessDimensions() method, and inside of it, you have a local variable "plot", which can be set to true, thus the plotting may get proceeded within the ProcessDimensions() method.

 

If executing built-in command "DIMREGEN" is the intention to update the dimensions in the dynamic block BEFORE plotting (I am not sure if it works without trying it myself), then it is obviously has no effect as you wished.

 

So, you need to fix your code like this:

1. Remove last a 2 or 3 lines of code from the ProcessDimensions(). That is, do not do the plotting inside the ProcessDimensions() method;

2. Let ProcessDimentions() return true/false; that is, when the dynamic block(s) with dimension is/are updated, the method would return true, meaning plotting is needed after the dimensions are processed.

3. If "DIMREGEN" indeed fix the dimension's offset in the dynamic plot, you DO NOT call in with SendStringToExecute(), because it would not be executed BEFORE your command method finishes. You can try Editor.Command("DIMREGEN") instead.

4. You need to get system variable "BACKGROUNDPLOT" to 0, not 3!

 

Also, I'd not recommend post code as picture, or as attachment (unless there is huge number of lines of code), it makes commenting your code rather difficult: I have constantly/repeatedly leave the comment text window and open the attached code file/picture to look at the code, and then close it and go back to the comment window to continue. Use the "</>" button to copy/paste code, so that the code can be browsed while commenting by simply scrolling the web page. Much easier.

 

 

 

Norman Yuan

Drive CAD With Code

EESignature

Message 7 of 7

madhukum339
Participant
Participant

Thanks @norman.yuan, this line fixed the issue. 

Editor.Command("DIMREGEN")