Recent Posts

Pages: [1] 2 3 ... 10
1
.NET / Re: Force Jig to Draw
« Last post by cincir on Today at 12:40:33 am »
you are close :-) not the update but the sampler
2
AutoLISP (Vanilla / Visual) / mark many radius at middle point of arc at once
« Last post by meja on May 23, 2015, 10:02:57 pm »
I have a code like this below
Code - Auto/Visual Lisp: [Select]
  1. (defun c:darp (/ oldos ent obj elst plst blst p par pd i pt ssl)
  2. (setq oldos (getvar "osmode"))
  3. (setvar "osmode" 0)
  4. (setq ent (car (entsel "\n SELECT arc in lwpolyline "))
  5.     obj (vlax-ename->vla-object ent)
  6.     elst (entget ent)
  7.     plst (list)
  8.     blst (list)
  9. )
  10. (foreach a elst
  11.   (if (= (car a) 10)
  12.       (setq plst (append plst (list (cdr a))))
  13.   )
  14.   (if (= (car a) 42)
  15.       (setq blst (append blst (list (cdr a))))
  16.   )
  17. )
  18. (setq i 0)
  19. (foreach b blst
  20.   (if (not (equal b 0 0.000001))
  21.       (progn
  22.                (setq p (nth i plst)
  23.                          par (vlax-curve-getparamatpoint obj p)
  24.                          pd (vlax-curve-getpointatparam obj (+ par 0.5))
  25.                )
  26.                (command "undo" "be")
  27.                (setq ssl  (acet-explode ent))
  28.                (setq pt (cdr (assoc 10 (entget (ssname ssl i)))))
  29.                (command "undo" "e")
  30.                (command "undo" 1)
  31.                (command "dimradius" pd (list (/ (+ (car pt) (car pd)) 2) (/ (+ (cadr pt)
  32.  
  33. (cadr pd)) 2)))
  34.       )
  35.   )
  36.   (setq i (1+ i))
  37. )
  38. (setvar "osmode" oldos)
  39. )
  40.  

NOW.i want to mark many arcs at once in my landscape job
HOW CAN REPEAT FUNCTION DO IT?
3
What do you want to do with Excel?
I am using  functions that I use for many years such:
Code - Auto/Visual Lisp: [Select]
  1. ; Function   : MsX_OpenNew
  2. ; Description: Opens a new WorkBooks of Excel 97, 2000, XP or >=2003
  3. ; Arguments  : display-mode > T = SHOW - nil = HIDE
  4. ; Example    : (MsX_LoadTypeLib) (MsX_OpenNew T)
  5. ;
  6. (defun MsX_OpenNew (DspMod)
  7.  (princ "\nCreating new Excel Spreadsheet file...")
  8.  (cond
  9.    ( (setq *ExclApp*  (vlax-get-or-create-object "Excel.Application"))
  10.      (setq
  11.        *XlAcWbk* (msxm-Add (vlax-get-property *ExclApp* 'WorkBooks))
  12.        *XlAcSht* (msxp-get-ActiveSheet *ExclApp*)
  13.        *XlAcCls* (msxp-get-Cells       *XlAcSht*)
  14.      )
  15.      (if DspMod (vla-put-visible *ExclApp* 1) (vla-put-visible *ExclApp* 0))
  16.    )
  17.    ( (alert "ERROR\n\nCannot initialize Excel.Application") )
  18.  )
  19. )
  20. (defun msxp-get-ActiveSheet        (ExlObj) (vlax-get-property  ExlObj 'ActiveSheet             ))
  21. (defun msxp-get-Cells              (ShtObj) (vlax-get-property  ShtObj 'Cells                   ))
  22. (defun msxm-Add                    (VlaObj) (vlax-invoke-method VlaObj 'Add                     ))
Why don't use something like (vlax-get-or-create-object "Microsoft.Excel") ???
I get a nil:Comando: (vlax-get-or-create-object "Microsoft.Excel")
nil

Now I get a new error from Office who fails to verify the license, see image (in this new Laptop I have "Office Home & Business 2013", just bought):

Code: [Select]
Comando: (setq *ExclApp*  (vlax-get-or-create-object "Excel.Application"))
#<VLA-OBJECT _Application 00000000253cd3d8>

Comando: (setq *XlAcWbk* (msxm-Add (vlax-get-property *ExclApp* 'WorkBooks)))
; errore: Il server ActiveX ha restituito un errore: La chiamata di procedura remota non riuscita

Comando: (setq *XlAcWbk* (msxm-Add (vlax-get-property *ExclApp* 'WorkBooks)))
; errore: Il server ActiveX ha restituito un errore: Server RPC non disponibile

Comando: (setq *ExclApp*  (vlax-get-or-create-object "Excel.Application"))
#<VLA-OBJECT _Application 00000000253caf68>

Comando: (setq *XlAcWbk* (msxm-Add (vlax-get-property *ExclApp* 'WorkBooks)))
; errore: Il server ActiveX ha restituito un errore: La chiamata di procedura remota non riuscita
:tickedoff:
no problems with Bricscad... :-)
4
.NET / Re: Get line lengths
« Last post by Coder on May 23, 2015, 02:08:56 am »
Thank you Keith Brown , I got the point from your example .  :-)
5
AutoLISP (Vanilla / Visual) / Re: Excel.Application error on AutoCAD/Excel 2013
« Last post by kpblc on May 23, 2015, 01:41:30 am »
What do you want to do with Excel? Why don't use something like
(vlax-get-or-create-object "Microsoft.Excel")
???
6
.NET / Re: Get line lengths
« Last post by Keith Brown on May 22, 2015, 10:49:29 pm »
It is outside the loop process , is not it ?

No it is not.  You are declaring a new line every time you iterate the for loop.  You should declare the line outside the loop and then set its value each time through the loop like Kerry said.  Something like below.

Code - C#: [Select]
  1.            if (psr.Status == PromptStatus.OK && psr.Value.Count > 0)
  2.                using (Transaction trans = db.TransactionManager.StartTransaction())
  3.                {
  4.                    Line line;
  5.                    foreach (SelectedObject item in psr.Value)
  6.                    {                
  7.                        line = (Line)trans.GetObject(item.ObjectId, OpenMode.ForWrite);
  8.  
  9.                        len += line.Length; /// <-- this len variable shows as an error
  10.                    }
  11.                    ed.WriteMessage("Lengths of line(s) :" + len.ToString());
  12.                    trans.Commit();
  13.                }
  14.            }
7
.NET / Re: F# - Use WPF dialog button to draw a line
« Last post by MickD on May 22, 2015, 07:32:17 pm »
Thank You Gile,
There is not much out there for F# WPF or with AutoCAD so every bit helps!

I'll try to take a closer look later today, there's a bit to absorb and test with here, thanks.
8
.NET / Re: F# - Use WPF dialog button to draw a line
« Last post by gile on May 22, 2015, 05:36:17 pm »
Hi,

Mick, I really thank you.
You have motivated me to get back a little to F# that I did not have much time to learn these days.
As I also try to learn WPF, mixing the two is fun.

Here's my last attempt. I tried to go a little further with WPF binding features and include some F# helpers (thanks to kaefer for this).
This time the window is run as a modal dialog, closed using DialogResult.

The Xaml
Code - XML: [Select]
  1. <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  2.        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  3.        xmlns:ViewModel="clr-namespace:ViewModel;assembly=AcadFsWpf2013"
  4.        Name="mainWindow"
  5.        Title="Draw Line"
  6.        WindowStartupLocation="CenterOwner" Height="120" Width="280" ResizeMode="NoResize">
  7.    <Window.DataContext>
  8.        <ViewModel:ViewModel/>
  9.    </Window.DataContext>
  10.    <Grid>
  11.        <StackPanel Orientation="Vertical">
  12.            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
  13.                <Label Content="Layer:" VerticalAlignment="Center"/>
  14.                <ComboBox x:Name="layers" Margin="10" Width="200" Height="25"
  15.                          ItemsSource="{Binding Layers}" SelectedItem="{Binding Layer}"/>
  16.            </StackPanel>
  17.            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
  18.                <Button x:Name="btnOK" Content="OK" Margin="10" Width="80" Height="25"
  19.                        Command="{Binding OkCommand}" CommandParameter="{Binding ElementName=mainWindow}"/>
  20.                <Button x:Name="btnCancel" Content="Cancel" Margin="10" Width="80" Height="25"
  21.                        Command="{Binding CancelCommand}" CommandParameter="{Binding ElementName=mainWindow}"/>
  22.            </StackPanel>
  23.        </StackPanel>
  24.    </Grid>
  25. </Window>

Model
Code - F#: [Select]
  1. namespace Model
  2.  
  3. open System
  4. open Autodesk.AutoCAD.ApplicationServices
  5. open Autodesk.AutoCAD.DatabaseServices
  6. open Autodesk.AutoCAD.EditorInput
  7. open Autodesk.AutoCAD.Geometry
  8. open Autodesk.AutoCAD.Runtime
  9.  
  10. type AcAp = Autodesk.AutoCAD.ApplicationServices.Application
  11. type AcEx = Autodesk.AutoCAD.Runtime.Exception
  12.  
  13. module Helpers =
  14.  
  15.    let getObject<'a when 'a :> DBObject> (id : ObjectId) =
  16.        id.GetObject(OpenMode.ForRead) :?> 'a
  17.  
  18.    let getObjects<'a when 'a :> DBObject>  : System.Collections.IEnumerable -> _ =
  19.        let rxc = RXClass.GetClass(typeof<'a>)
  20.        Seq.cast<ObjectId>
  21.        >> Seq.choose (function
  22.            | id when id.ObjectClass.IsDerivedFrom(rxc) -> Some(getObject<'a> id)
  23.            | _ -> None)
  24.  
  25.    let addEntity (ent : #Entity) (btr : BlockTableRecord) =
  26.        if not btr.IsWriteEnabled then btr.UpgradeOpen()
  27.        let id = btr.AppendEntity(ent)
  28.        btr.Database.TransactionManager.AddNewlyCreatedDBObject(ent, true)
  29.        id
  30.  
  31.    type OptionBuilder() =
  32.        member b.Bind(x, f) = Option.bind f x
  33.        member b.Return(x) = Some x
  34.        member b.Zero() = None
  35.  
  36.    let opt = new OptionBuilder()
  37.  
  38.    let failIfNotOk (pr : #PromptResult) =
  39.        opt { if pr.Status = PromptStatus.OK then return pr }
  40.  
  41.    type Editor with
  42.        member ed.GetPoint(pt, msg) =
  43.            ed.GetPoint(new PromptPointOptions(msg, BasePoint = pt, UseBasePoint = true))
  44.  
  45. open Helpers
  46.  
  47. module CadWorker =
  48.  
  49.    let getLayers () =
  50.        let db = HostApplicationServices.WorkingDatabase
  51.        use tr = db.TransactionManager.StartTransaction()
  52.        db.LayerTableId
  53.        |> getObject<LayerTable>
  54.        |> getObjects<LayerTableRecord>
  55.        |> Seq.map (fun l -> l.Name)
  56.        |> Seq.toArray
  57.  
  58.    let drawLine (layer) =
  59.        let doc = AcAp.DocumentManager.MdiActiveDocument
  60.        let db = doc.Database
  61.        let ed = doc.Editor
  62.        let result = opt {
  63.            let! pr1 = failIfNotOk (ed.GetPoint("\nStart point: "))
  64.            let! pr2 = failIfNotOk (ed.GetPoint(pr1.Value, "\nEnd point: "))
  65.            return (pr1, pr2) }
  66.        match result with
  67.        | None -> ()
  68.        | Some (pr1, pr2) ->
  69.            use tr = db.TransactionManager.StartTransaction()
  70.            db.CurrentSpaceId
  71.            |> getObject<BlockTableRecord>
  72.            |> addEntity (new Line(pr1.Value, pr2.Value, Layer = layer)) |> ignore
  73.            tr.Commit();

View
Code - F#: [Select]
  1. namespace View
  2.  
  3. open System
  4. open System.IO
  5. open System.Windows
  6. open System.Windows.Markup
  7. open System.Xaml
  8. open Autodesk.AutoCAD.ApplicationServices
  9. open Autodesk.AutoCAD.Runtime
  10.  
  11. type AcAp = Autodesk.AutoCAD.ApplicationServices.Application
  12.  
  13. type CommandMethods() =
  14.    [<CommandMethod("Test")>]
  15.    member x.Test () =
  16.        let win = XamlReader.Load(File.OpenRead("MainWindow.xaml")) :?> Window
  17.        AcAp.ShowModalWindow(win) |> ignore
  18.  
  19. [<assembly: CommandClass(typeof<CommandMethods>)>]
  20. do ()

ViewModel
Code - F#: [Select]
  1. namespace ViewModel
  2.  
  3. open System
  4. open System.ComponentModel
  5. open System.Windows
  6. open System.Windows.Input
  7.  
  8. type ViewModelBase() =
  9.    let propertyChangedEvent = new DelegateEvent<PropertyChangedEventHandler>()
  10.    interface INotifyPropertyChanged with
  11.        [<CLIEvent>]
  12.        member x.PropertyChanged = propertyChangedEvent.Publish
  13.    member x.OnPropertyChanged propertyName =
  14.        propertyChangedEvent.Trigger([| x; new PropertyChangedEventArgs(propertyName) |])
  15.  
  16. type RelayCommand (canExecute:(obj -> bool), action:(obj -> unit)) =
  17.    let event = new DelegateEvent<EventHandler>()
  18.    interface ICommand with
  19.        [<CLIEvent>]
  20.        member x.CanExecuteChanged = event.Publish
  21.        member x.CanExecute arg = canExecute(arg)
  22.        member x.Execute arg = action(arg)
  23.  
  24. open Model.CadWorker
  25.  
  26. type ViewModel() =
  27.    inherit ViewModelBase()
  28.  
  29.    let mutable layer = "0"
  30.  
  31.    let resultOk param =
  32.        (unbox<Window> param).DialogResult <- Nullable(true)
  33.        drawLine(layer)
  34.  
  35.    let resultCancel param =
  36.        (unbox<Window> param).DialogResult <- Nullable(false)
  37.  
  38.    member x.Layer
  39.        with get () = layer
  40.        and set v = layer <- v
  41.  
  42.    member x.Layers
  43.        with get () = getLayers()
  44.  
  45.    member x.OkCommand =
  46.        new RelayCommand((fun _ -> true), resultOk)  
  47.  
  48.    member x.CancelCommand =
  49.        new RelayCommand((fun _ -> true), resultCancel)
  50.  
  51.  
9
.NET / Re: Get line lengths
« Last post by Coder on May 22, 2015, 01:29:52 pm »
Go into debug mode, put a breakpoint at the line = statement, check your variable values as you iterate the psr .. that may help.
I could not get into debug mode due to the error that is in the program .
BTW .
A cheaper process is to declare the line variable outside the loop and just assign a value as you iterate rather than declare and assign at each step
It is outside the loop process , is not it ?

... and more importantly ... why are you forcing the getObject to a Line ... doesn't your selection process ensure that it is a line ??
I could not come with an alternative one than this one , can you offer your idea please ?

added: and why are you setting OpenMode to ForWrite ??
Yes it supposed to be ForRead and not ForWrite , you are right .

Thank you.
10
.NET / Re: Force Jig to Draw
« Last post by Keith Brown on May 22, 2015, 01:21:04 pm »
Not at my pc but isn't that what the update method is for?
Pages: [1] 2 3 ... 10