<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Need help to set the TARGET variable zero in C#. in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/need-help-to-set-the-target-variable-zero-in-c/m-p/13107331#M2171</link>
    <description>&lt;P&gt;Hey everyone!&lt;/P&gt;&lt;P&gt;As you can see from the title, I've tried changing the TARGET value, but it also changes the view in the model. How can I do this without affecting the view in the model tab?&lt;/P&gt;&lt;P&gt;Any help would be greatly appreciated. Thank you!&lt;/P&gt;&lt;LI-CODE lang="general"&gt;private void ResetTarget()
{
    using (Transaction tr = db.TransactionManager.StartTransaction())
    {
        try
        {
            ViewTableRecord vtr = ed.GetCurrentView();
            vtr.Target = new Point3d(0, 0, 0);
            ed.SetCurrentView(vtr);

            tr.Commit();

        }
        catch (Exception ex)
        {
            ed.WriteMessage($"\nError in ResetTarget function: {ex.Message}");
        }
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 25 Oct 2024 04:58:20 GMT</pubDate>
    <dc:creator>luckyboy82292</dc:creator>
    <dc:date>2024-10-25T04:58:20Z</dc:date>
    <item>
      <title>Need help to set the TARGET variable zero in C#.</title>
      <link>https://forums.autodesk.com/t5/net-forum/need-help-to-set-the-target-variable-zero-in-c/m-p/13107331#M2171</link>
      <description>&lt;P&gt;Hey everyone!&lt;/P&gt;&lt;P&gt;As you can see from the title, I've tried changing the TARGET value, but it also changes the view in the model. How can I do this without affecting the view in the model tab?&lt;/P&gt;&lt;P&gt;Any help would be greatly appreciated. Thank you!&lt;/P&gt;&lt;LI-CODE lang="general"&gt;private void ResetTarget()
{
    using (Transaction tr = db.TransactionManager.StartTransaction())
    {
        try
        {
            ViewTableRecord vtr = ed.GetCurrentView();
            vtr.Target = new Point3d(0, 0, 0);
            ed.SetCurrentView(vtr);

            tr.Commit();

        }
        catch (Exception ex)
        {
            ed.WriteMessage($"\nError in ResetTarget function: {ex.Message}");
        }
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Oct 2024 04:58:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/need-help-to-set-the-target-variable-zero-in-c/m-p/13107331#M2171</guid>
      <dc:creator>luckyboy82292</dc:creator>
      <dc:date>2024-10-25T04:58:20Z</dc:date>
    </item>
    <item>
      <title>Re: Need help to set the TARGET variable zero in C#.</title>
      <link>https://forums.autodesk.com/t5/net-forum/need-help-to-set-the-target-variable-zero-in-c/m-p/13108807#M2172</link>
      <description>&lt;P&gt;Your question doesn't make sense.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The Target property defines the center point of a view. If you apply a ViewTableRecord to the current view, it is going to modify the view to have the target specified in the ViewTableRecord.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Oct 2024 17:14:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/need-help-to-set-the-target-variable-zero-in-c/m-p/13108807#M2172</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2024-10-25T17:14:04Z</dc:date>
    </item>
    <item>
      <title>Re: Need help to set the TARGET variable zero in C#.</title>
      <link>https://forums.autodesk.com/t5/net-forum/need-help-to-set-the-target-variable-zero-in-c/m-p/13112268#M2173</link>
      <description>&lt;P&gt;May we Zoom Extents in a new created side database before saving it? Or set an initial view?&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2024 07:47:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/need-help-to-set-the-target-variable-zero-in-c/m-p/13112268#M2173</guid>
      <dc:creator>luckyboy82292</dc:creator>
      <dc:date>2024-10-28T07:47:15Z</dc:date>
    </item>
    <item>
      <title>Re: Need help to set the TARGET variable zero in C#.</title>
      <link>https://forums.autodesk.com/t5/net-forum/need-help-to-set-the-target-variable-zero-in-c/m-p/13125808#M2174</link>
      <description>&lt;P&gt;I just found a solution when the TARGET is not equal to zero. The TARGET variable affects the plot window coordinates constantly. So, the solution is to create a translation matrix for it and always transform the plot window coordinates using this translation matrix. My code looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;private Matrix3d GetTranslationMatrixFromTarget()
{
    try
    {
        ViewTableRecord vtr = ed.GetCurrentView();
        Point3d targetPoint = vtr.Target;

        if (!targetPoint.IsEqualTo(Point3d.Origin))
        {
            Matrix3d translationMatrix = Matrix3d.Displacement(-targetPoint.GetAsVector());

            return translationMatrix;
        }
        else
        {
            return Matrix3d.Identity;
        }
    }
    catch (Exception ex)
    {
        ed.WriteMessage($"\nError in GetTranslationMatrixFromTarget function: {ex.Message}");
        return Matrix3d.Identity;
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;And used like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;private void ValidateAndPlot(Layout layOut, Point3d point0, Point3d point1, string path, string fileName, PlotProgressDialog pd)
{
    Matrix3d matrix3D = GetTranslationMatrixFromTarget();
    point0 = point0.TransformBy(matrix3D);
    point1 = point1.TransformBy(matrix3D);
    Point2d min = new Point2d(point0.X, point0.Y);
    Point2d max = new Point2d(point1.X, point1.Y);
    string style = layOut.CurrentStyleSheet;
    if (style == string.Empty)
    {
        style = "acad.ctb";
    }
    string plotDeviceName = "DWG To PDF.pc3";
    Extents2d pw = new Extents2d(min, max);

    try
    {
        using (PlotInfo pi = new PlotInfo())
        {
            pi.Layout = layOut.ObjectId;

            using (PlotSettings ps = new PlotSettings(layOut.ModelType))
            {
                ps.CopyFrom(layOut);
                PlotSettingsValidator psv = PlotSettingsValidator.Current;
                psv.SetPlotWindowArea(ps, pw);
                psv.SetPlotType(ps, Autodesk.AutoCAD.DatabaseServices.PlotType.Window);
                psv.SetPlotConfigurationName(ps, plotDeviceName, layOut.CanonicalMediaName);
                if (ps.CurrentStyleSheet == string.Empty)
                {
                    psv.SetCurrentStyleSheet(ps, style);
                }
                psv.SetPlotPaperUnits(ps, layOut.PlotPaperUnits);
                psv.SetUseStandardScale(ps, true);
                psv.SetStdScaleType(ps, StdScaleType.ScaleToFit);
                psv.SetPlotCentered(ps, true);
                psv.SetPlotRotation(ps, layOut.PlotRotation);
                pi.OverrideSettings = ps;

                using (PlotInfoValidator piv = new PlotInfoValidator())
                {
                    piv.MediaMatchingPolicy = MatchingPolicy.MatchEnabled;
                    piv.Validate(pi);

                    if (PlotFactory.ProcessPlotState == ProcessPlotState.NotPlotting)
                    {
                        using (PlotEngine pe = PlotFactory.CreatePublishEngine())
                        {
                            pd.OnBeginPlot();
                            pe.BeginPlot(pd, null);
                            pe.BeginDocument(pi, null, null, 0, true, Path.Combine($"{path}\\{fileName}.pdf"));

                            pd.set_PlotMsgString(PlotMessageIndex.SheetProgressCaption, $"Plotting: {fileName}");
                            pd.OnBeginSheet();
                            PlotPageInfo ppi = new PlotPageInfo();
                            pe.BeginPage(ppi, pi, true, null);
                            pe.BeginGenerateGraphics(null);
                            pe.EndGenerateGraphics(null);

                            pd.SheetProgressPos = 100;
                            pd.OnEndSheet();
                            pe.EndPage(null);

                            pe.EndDocument(null);
                            pd.OnEndPlot();
                            pe.EndPlot(null);
                        }
                    }
                    else
                    {
                        throw new InvalidOperationException("Plot engine is in an invalid state.");
                    }
                }
            }
        }
    }
    catch (Exception ex)
    {
        throw new Exception($"{ex.Message}");
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 02 Nov 2024 09:12:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/need-help-to-set-the-target-variable-zero-in-c/m-p/13125808#M2174</guid>
      <dc:creator>luckyboy82292</dc:creator>
      <dc:date>2024-11-02T09:12:11Z</dc:date>
    </item>
    <item>
      <title>Re: Need help to set the TARGET variable zero in C#.</title>
      <link>https://forums.autodesk.com/t5/net-forum/need-help-to-set-the-target-variable-zero-in-c/m-p/13126755#M2175</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/13002699"&gt;@luckyboy82292&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;May we Zoom Extents in a new created side database before saving it? Or set an initial view?&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;You can open the ViewportTableRecord having the name "*Active" and modify it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 03 Nov 2024 06:38:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/need-help-to-set-the-target-variable-zero-in-c/m-p/13126755#M2175</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2024-11-03T06:38:47Z</dc:date>
    </item>
  </channel>
</rss>

